From e4deb217d116624f9f259d2f50825be8e7c7c008 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Mon, 12 Apr 2010 15:53:18 +0000 Subject: [PATCH] Problem 014 git-svn-id: file:///srv/svn/euler@39 e5f4c3ec-3c0c-11df-b522-21efaa4426b5 --- e014.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 e014.py diff --git a/e014.py b/e014.py new file mode 100644 index 0000000..ebde863 --- /dev/null +++ b/e014.py @@ -0,0 +1,20 @@ +def collatz(n): + steps = 0 + while n > 1: + steps = steps + 1 + if n % 2: + n = 3 * n + 1 + else: + n = n / 2 + return steps + +i = 1000000 +max = 0 +maxnum = i +while i > 1: + i = i - 1 + c = collatz(i) + if c > max: + max = c + maxnum = i +print 'Max was {0} steps for {1}'.format(max, maxnum)