So my question is about the collatz conjecture. The task is that I have to write a code which counts the length of steps of each conjecture. For example 2 = 2/2 = 1
is one step.
Now I need to know how many start numbers between 1 and 10000 have 111+ steps. I get 54 on my code but I don't have any sources wether its right or wrong.
anzahl
should be the counter of how many numbers have 111 steps and laenge
is the length of each number:
public class Collertz {
public static void main(String[] args) {
int max = 111;
int anzahl = 0;
int laenge = 0;
for(int i=0; i<=10000;i++) {
for (int j = i; i>1; i++) {
if (j%2 == 0) {
j = j/2;
laenge++;
}
else {
j = 3*j+1;
laenge++;
}
}
if (laenge >= max) {
anzahl++;
}
}
System.out.println(anzahl);
}
}