Created
December 16, 2011 20:54
-
-
Save jakedobkin/1487926 to your computer and use it in GitHub Desktop.
Euler 57: Continued Fractions
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
| # http://projecteuler.net/problem=58 | |
| # i found this confusing, so i worked through dreamshire's analysis | |
| # numerator is always = numerator + denominator * 2 | |
| # denominator is = numerator + denominator | |
| # starting with numerator 3 and denominator 2 | |
| # which is round 1, so start at round 2 | |
| numerator = 3 | |
| denominator = 2 | |
| count = 0 | |
| for x in range (2,1000): | |
| # this is a smart way to set them so you don't have to use an intermediate var | |
| numerator, denominator = numerator + denominator * 2, numerator + denominator | |
| if len(str(numerator)) > len(str(denominator)): | |
| count = count + 1 | |
| print count | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
interestingly, before i understood dreamshire's version, i ended up computing a recursive version of the sqrt of 2-