Skip to content

Commit

Permalink
Completed basic implementation and made all tests green. Closes #8 and
Browse files Browse the repository at this point in the history
  • Loading branch information
lapluviosilla committed Jan 31, 2014
1 parent e7a2e56 commit 90bc97e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Collatz.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,29 @@ def collatz_eval (i, j) :
"""
assert(i > 0)
assert(j > 0)
# <your code>
v = 1
assert(v > 0)
return v
start = min(i, j)
end = max(i, j)
max_cycle_length = 1
for n in range(start, end+1) :
cycles = collatz_cycles(n)
if cycles > max_cycle_length: max_cycle_length = cycles
assert(max_cycle_length > 0)
return max_cycle_length

# -------------
# collatz_cycles
# -------------
def collatz_cycles (num) :
assert(num > 0)
assert(num < 1000000)
cycles = 1
while(num != 1) :
if num % 2 == 0:
num = num // 2
else:
num = 3*num + 1
cycles += 1
assert(cycles > 0)
return cycles


Expand Down

0 comments on commit 90bc97e

Please sign in to comment.