Created
October 10, 2011 01:12
-
-
Save hale/1274446 to your computer and use it in GitHub Desktop.
sanna3n
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Main class | |
* @author Susanna Kempe | |
* @version 10th October 2011 | |
*/ | |
public class Main { | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
int lower; | |
int upper; | |
int max = 0; | |
int count; | |
long numberCopy; | |
lower = Integer.parseInt(args[0]); | |
upper = Integer.parseInt(args[1]); | |
for (long i= upper; i >= lower; i--) { | |
count = 2; | |
numberCopy = i; | |
while (numberCopy != 2) { | |
count++; | |
numberCopy = (((numberCopy&1)) == 0) ? numberCopy>>1 : (3*numberCopy) +1; | |
if ((numberCopy&1) == 0) { | |
numberCopy = numberCopy >> 1; | |
} | |
else { | |
numberCopy = (3* numberCopy) +1; | |
} | |
} | |
if (count > max) { | |
max = count; | |
} | |
} | |
System.out.println(lower + " " + upper + " " + max); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment