Last active
September 4, 2015 12:44
-
-
Save mgedmin/323897 to your computer and use it in GitHub Desktop.
Project Euler problem 14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# refactoring of http://sandrotosi.blogspot.com/2010/03/project-euler-problem-14.html | |
cache = {1: 1} | |
def collatz(n): | |
if n not in cache: | |
if n % 2 == 0: | |
cache[n] = 1 + collatz(n/2) | |
else: | |
cache[n] = 1 + collatz(3*n + 1) | |
return cache[n] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment