mirror of
https://github.com/correl/euler.git
synced 2024-11-23 19:19:53 +00:00
Problem 014
git-svn-id: file:///srv/svn/euler@39 e5f4c3ec-3c0c-11df-b522-21efaa4426b5
This commit is contained in:
parent
5114433f37
commit
e4deb217d1
1 changed files with 20 additions and 0 deletions
20
e014.py
Normal file
20
e014.py
Normal file
|
@ -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)
|
Loading…
Reference in a new issue