From 6be964e159238273bd7f89101d994a7105d053dc Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Mon, 21 Dec 2015 10:55:34 +0100 Subject: [PATCH] Added problem 14 --- 14.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+), 0 deletions(-) create mode 100755 14.py 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 -- libgit2 0.22.2