Created
December 20, 2011 21:08
-
-
Save jakedobkin/1503279 to your computer and use it in GitHub Desktop.
Euler 65
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
| # 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