Skip to content

Instantly share code, notes, and snippets.

@rawsh
Created February 1, 2017 05:00
Show Gist options
  • Select an option

  • Save rawsh/329fc9d83338ed9bea6c97f5566ed2fe to your computer and use it in GitHub Desktop.

Select an option

Save rawsh/329fc9d83338ed9bea6c97f5566ed2fe to your computer and use it in GitHub Desktop.
import sys
known = {0:1,1:1,2:1}
def sequence(n):
if n in known:
return known[n]
else:
x = 2*sequence(n-1) + 2*sequence(n-2) + 2*sequence(n-3)
known[n] = x
return x
def ratio(n):
x = sequence(n)
y = sequence(n-1)
return x/float(y)
sys.setrecursionlimit(150000)
for x in range(3,100):
print ratio(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment