Skip to content

Instantly share code, notes, and snippets.

@hale
Created October 9, 2011 23:35
Show Gist options
  • Save hale/1274369 to your computer and use it in GitHub Desktop.
Save hale/1274369 to your computer and use it in GitHub Desktop.
HailstoneLengthQuick
public class HailstoneLengthQuick {
public static void main(String[] args) {
int max = 0;
int lower = Integer.parseInt(args[0]);
int upper = Integer.parseInt(args[1]);
for (long n = upper; n >= lower; n--) {
long workingN = n;
int count = 2;
while (workingN!=2) {
count++;
workingN = ((workingN&1) == 0) ? workingN>>1 : (3*workingN) +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