Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created December 20, 2011 21:08
Show Gist options
  • Select an option

  • Save jakedobkin/1503279 to your computer and use it in GitHub Desktop.

Select an option

Save jakedobkin/1503279 to your computer and use it in GitHub Desktop.
Euler 65
# pattern in convergents of e
# 1 + 2 * 1 = 3
# 2 + 3 * 2 = 8
# 3 + 8 * 1 = 11
# new term = two terms ago + one term ago * i
def make_e(n):
CF = [2]
c = 1
while len(CF)<n:
CF = CF + [1,2*c,1]
c += 1
return CF
nlist = make_e(100)
start = [2,3]
for i in range (2,100):
newterm = start[i-2] + start[i-1]*nlist[i]
start.append(newterm)
print i+1,newterm
sum = 0
for j in range (0,len(str(newterm))):
digit = str(newterm)[j:j+1]
sum = sum+int(digit)
print sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment