-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem14.java
More file actions
42 lines (31 loc) · 759 Bytes
/
Problem14.java
File metadata and controls
42 lines (31 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
public class Problem14 {
public static void main(String[] args){
int maxChainCount = Integer.MIN_VALUE;
int maxChainElement = Integer.MIN_VALUE;
int currentCount = 0;
for( int i = 13; i < 1000000; i++){
currentCount = getChainCount(i);
if(currentCount > maxChainCount){
maxChainCount = currentCount;
maxChainElement = i;
}
}
System.out.println("Result: " + maxChainElement);
}
public static int getChainCount(int x){
int count = 0;
long start = x;
while(start > 1){
count++;
if(start % 2 == 0){
start = start/2;
}
else {
start = (3*start) + 1;
}
}
if (( x == 910107 ) || (x == 837799))
System.out.println("Num: " + x + " count: " + count);
return count;
}
}