Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created December 16, 2011 20:54
Show Gist options
  • Select an option

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

Select an option

Save jakedobkin/1487926 to your computer and use it in GitHub Desktop.
Euler 57: Continued Fractions
# 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
@jakedobkin
Copy link
Author

interestingly, before i understood dreamshire's version, i ended up computing a recursive version of the sqrt of 2-


def a(n):
    if n == 1:
        return 1.5
    return (a(n-1)+2/a(n-1))/2

print a(10)```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment