Creating a Loop for Sum of Digit Squares to Equal 1

  • Context: Fortran 
  • Thread starter Thread starter d-star
  • Start date Start date
  • Tags Tags
    Loop Squares Sum
Click For Summary

Discussion Overview

The discussion revolves around creating a Fortran program that loops through numbers from 1 to a user-defined limit, determining whether the sum of the squares of the digits of each number eventually equals 1. This involves identifying numbers that meet this criterion and those that do not, as well as implementing a function to facilitate this process.

Discussion Character

  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant describes the criteria for numbers to reach 1 through the sum of the squares of their digits and provides examples with numbers 7 and 13.
  • Another participant suggests formalizing the existing code into a function that can be called within a loop to check each number from 1 to x.
  • The original poster expresses a need to identify whether sequences reach 1 or continue indefinitely, indicating a requirement for a TRUE/FALSE output for each number.
  • The original poster shares a partial code snippet and seeks further suggestions on how to implement the necessary logic for their program.

Areas of Agreement / Disagreement

Participants generally agree on the approach of using a function to encapsulate the logic for calculating the sum of squares, but the discussion remains unresolved regarding the implementation details for identifying sequences that do not reach 1.

Contextual Notes

The original poster's code snippet is incomplete and lacks the necessary logic to check for sequences that do not reach 1, which may depend on additional assumptions or definitions not fully articulated in the discussion.

d-star
Messages
8
Reaction score
0
Hi, I'm writing a program in fortran that basically creates a loop from 1 until a certain number x (input by the user), and goes through each value between 1 and the certain number x in order to determine if each value meets certain criteria. The criteria is that the sum of the square of the individual digits created by each value in between 1 and x (where each value is taken from the preceding sum), must eventually equal 1. For example, the number 7 meets this criteria, because when we take the sum of the square of the individual digits, (7^2)=49, (4^2)+(9^2)=97, (9^2)+(7^2)=130, (1^2)+(3^2)+(0^2)=10, (1^2)+(0^2)= 1. The same goes for the number 13, except this reaches 1 after only two steps: (1^2)+(3^2)=10, (1^2)+(0^2)= 1.
I have already wrote the program for calculating the sum of the square of the individual digits of a number, and eventually reaching 1. Although I am having trouble finding a function to use in order to go through each number from 1 to a certain value x, and determining whether each number in between 1 and x meets this criteria or not.
Any help would be appreciated! Thanks!
 
Technology news on Phys.org


d-star said:
Hi, I'm writing a program in fortran that basically creates a loop from 1 until a certain number x (input by the user), and goes through each value between 1 and the certain number x in order to determine if each value meets certain criteria. The criteria is that the sum of the square of the individual digits created by each value in between 1 and x (where each value is taken from the preceding sum), must eventually equal 1. For example, the number 7 meets this criteria, because when we take the sum of the square of the individual digits, (7^2)=49, (4^2)+(9^2)=97, (9^2)+(7^2)=130, (1^2)+(3^2)+(0^2)=10, (1^2)+(0^2)= 1. The same goes for the number 13, except this reaches 1 after only two steps: (1^2)+(3^2)=10, (1^2)+(0^2)= 1.
I have already wrote the program for calculating the sum of the square of the individual digits of a number, and eventually reaching 1. Although I am having trouble finding a function to use in order to go through each number from 1 to a certain value x, and determining whether each number in between 1 and x meets this criteria or not.
Any help would be appreciated! Thanks!

What have you tried?
 


You are having trouble finding a function to use? You already wrote it! Just make a formal function out of your code and call it from within the loop of n = 1, x
 


alright, thanks! it actually had a suspicion that that was the case. Although I have another question as well.
I also need to integrate a way that basically identifies if each value from 1 to x satisfies the condition that its sequence eventually reaches 1, and I also need to make my program identify if the sequence does not reach 1 (goes on forever). So if the number reaches 1 it is TRUE, and if does not reach 1 (goes on forever) then it is FALSE. I then need to be able to list all the numbers between 1 and x that are TRUE(sequence reaches 1). So far I have:

PROGRAM S
IMPLICIT NONE

INTEGER :: x,j,a
READ (*,*) x
j = 1

DO a = 1,x
CALL S
j = j +1
END DO

END PROGRAM S2


(where S is my function that solves for the square of the sum of the individual digits from 1 to x, determining if each number's sequence reaches 1 or not)

Any suggestions? Thanks!
 

Similar threads

Replies
5
Views
1K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 23 ·
Replies
23
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
11
Views
2K