Created
October 9, 2011 23:35
-
-
Save hale/1274369 to your computer and use it in GitHub Desktop.
HailstoneLengthQuick
This file contains hidden or 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
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