Created
October 24, 2013 21:33
-
-
Save david-batranu/7145427 to your computer and use it in GitHub Desktop.
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
#include <stdio.h> | |
#include <stdlib.h> | |
int main(){ | |
unsigned int maxRecord = 0; | |
unsigned int upperBound = 1000000; | |
unsigned int chainLen[upperBound + 1]; | |
size_t x; | |
int max_x; | |
for(x = 1; x < upperBound; ++x) { | |
unsigned int n = x; | |
unsigned int max = 0; | |
while(n != 1) { | |
if(n < upperBound && chainLen[n] != 0 && chainLen[n] + max < maxRecord) {break;} | |
if(n % 2 == 0) {n /= 2;} | |
else {n = (n * 3 + 1);} | |
max++; | |
} | |
chainLen[x] = max; | |
if(max >= maxRecord) { | |
maxRecord = max; | |
max_x = x; | |
} | |
} | |
fprintf(stdout, "%u\n", max_x); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment