Created
December 24, 2011 15:31
-
-
Save jakedobkin/1517560 to your computer and use it in GitHub Desktop.
Euler Problem 71
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
| 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