Fortran Creating a Loop for Sum of Digit Squares to Equal 1

  • Thread starter Thread starter d-star
  • Start date Start date
  • Tags Tags
    Loop Squares Sum
AI Thread Summary
The discussion centers on creating a Fortran program that evaluates numbers from 1 to a user-defined limit (x) to determine if the sum of the squares of their digits eventually equals 1. The user has successfully implemented a function to calculate the sum of the squares but seeks guidance on structuring a loop to apply this function to each number in the specified range. The main challenge involves identifying whether each number's sequence reaches 1 (TRUE) or continues indefinitely (FALSE). The user aims to compile a list of numbers that meet the TRUE condition. Suggestions include formalizing the existing code into a callable function and utilizing it within a loop to check each number from 1 to x. The user has shared a partial code snippet and is looking for further recommendations on how to implement the logic for tracking and displaying results based on the criteria established.
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!
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
4
Views
1K
Replies
11
Views
2K
Replies
23
Views
3K
Replies
2
Views
2K
Replies
1
Views
2K
Replies
2
Views
2K
Back
Top