Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created December 24, 2011 15:31
Show Gist options
  • Select an option

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

Select an option

Save jakedobkin/1517560 to your computer and use it in GitHub Desktop.
Euler Problem 71
from fractions import Fraction, gcd
from math import floor
# n /d < 3/7
# so n < d*(3/7)
# so for each denominator, we'll look for the closest n that satisfies this equation
# if n and d have gcd==1, then they're a reduced fraction
# and the last one should be the closest fraction to 3/7 under 1MM
for d in range (1,1000000):
n = floor(d*(3.0/7.0))
if gcd(n,d)==1:
print n,d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment