diff --git a/14.py b/14.py new file mode 100755 index 0000000..8e1b0a5 --- /dev/null +++ b/14.py @@ -0,0 +1,26 @@ +#!/usr/bin/python + +import sys; +import math; + +lim = 1000000 +maxLength = 0 +maxChain = 0 + +def collatz(num): + counter = 1 + while(num is not 1): + if(num % 2 == 0): + num /= 2 + else: + num = num*3 + 1 + counter += 1 + return counter + +for i in range(1,lim): + length = collatz(i) + if(length > maxLength): + maxLength = length + maxChain = i + +print maxChain