Skip to content

Instantly share code, notes, and snippets.

@hale
Created October 10, 2011 01:12
Show Gist options
  • Save hale/1274446 to your computer and use it in GitHub Desktop.
Save hale/1274446 to your computer and use it in GitHub Desktop.
sanna3n
/**
* 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