Commit 6be964e159238273bd7f89101d994a7105d053dc

Authored by Imanol-Mikel Barba Sabariego
1 parent 9d3413fc

Added problem 14

Showing 1 changed file with 26 additions and 0 deletions
14.py 0 → 100755
  1 +#!/usr/bin/python
  2 +
  3 +import sys;
  4 +import math;
  5 +
  6 +lim = 1000000
  7 +maxLength = 0
  8 +maxChain = 0
  9 +
  10 +def collatz(num):
  11 + counter = 1
  12 + while(num is not 1):
  13 + if(num % 2 == 0):
  14 + num /= 2
  15 + else:
  16 + num = num*3 + 1
  17 + counter += 1
  18 + return counter
  19 +
  20 +for i in range(1,lim):
  21 + length = collatz(i)
  22 + if(length > maxLength):
  23 + maxLength = length
  24 + maxChain = i
  25 +
  26 +print maxChain