Skip to content

Instantly share code, notes, and snippets.

@yjh0502
Created March 21, 2013 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yjh0502/5209979 to your computer and use it in GitHub Desktop.
Save yjh0502/5209979 to your computer and use it in GitHub Desktop.
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