Created
March 21, 2013 01:22
-
-
Save yjh0502/5209979 to your computer and use it in GitHub Desktop.
This file contains 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
mem = {} #simple memorization | |
def byun_count(years): | |
if years in mem: | |
return mem[years] | |
count = 1 | |
life = years | |
while life > 0: | |
for i in range(2): | |
life -= 1 | |
count += byun_count(life) | |
if life == 0: | |
break | |
life -= 2 # absence | |
if life <= 0: | |
break | |
mem[years] = count | |
return count | |
assert byun_count(0) == 1 | |
assert byun_count(1) == 2 | |
assert byun_count(2) == 4 | |
assert byun_count(3) == 7 | |
assert byun_count(4) == 12 | |
print(byun_count(100)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment