Schools out now, and for my final grade my programming teacher gave us the option to come up with our own project to research about, problem solve, code, and present to the class. My project dealt with the Collatz conjecture just because some friends of mine who i visited last year during the AOTM summer camp told me about it, and got me extremely interested in how it works.
For people who don't know what the Collatz conjecture is; basically all it states is that if you have a even number plug that number into this equation: n/2, and if you have an odd number use this equation: 3n+1. The Conjecture states that no matter what number you put in, you will eventually end up at the number 1.
For example, the number 3:
3 is odd so we use 3n+1
3(3)+1 = 10
10 is even so we use n/2
10/2 = 5 3(5)+ 1 = 16 16/2 = 8 8/2 = 4 4/2 = 2 2/2 = 1
More information here
Given these standards, we can see that each number has a given number of "steps", or number of times you have to use the conjecture to reach the number 1. So like for the number 3 we got 3, 10, 5, 16, 8, 4, 2 , and 1 which is 8 steps(7 if 3 is not included). Here is where my final project comes into play. I asked myself the question "If given the number of steps, can we find the number or numbers that have that amount of steps? In other words, if i was to say "what number has 8 steps?" how could i find that number, and whether or not there are multiple numbers that have that many steps.
So basically my question is can we find all real numbers that derive from the steps of any real number using the Collatz conjecture.
To do this a friend of mine and I came together and wrote this code in java that basically inputs a number starting from 1 into the Collatz conjecture. Then it counts the number of steps it takes for that number, then checks to see if the number of steps matches the number inputted by the user. If the number of steps does not match the number asked then it tries the next number and so on.
The written code can be found here
This code works and all and i got a 100 on my final grade for it, but it doesn't answer the question of finding all integers. Instead, the program just finds the first number and sends it to the user.
TL;DR How can I update my code so that it lists ALL of the numbers that have the given number of steps?