#Project Euler Question 71
#By listing the set of reduced proper fractions for d ≤ 1,000,000 in ascending order of size, 
#find the numerator of the fraction immediately to the left of 3/7.

import math

def proper_fraction(x, y, z):
    frac_check = y/z
    closest_frac = 0
    frac_diff = frac_check - closest_frac
    closest_n = 1
    jump = 1
    for d in range(1, x+1):
        if d % 2 == 0:
            jump = 2
        else:
            jump = 1
        for n in range(closest_n, d, jump):
            frac = n / d
            if frac >= frac_check:
                break
            check = frac_check - frac
            if check < frac_diff:
                closest_frac = frac
                closest_ratio = (n, d)
                closest_n = n
                frac_diff = check
    print (closest_frac)
    return closest_ratio



print (proper_fraction(1000000, 3, 7))
#Project Euler Question 71
#By listing the set of reduced proper fractions for d ≤ 1,000,000 in ascending order of size, 
#find the numerator of the fraction immediately to the left of 3/7.

import math

def proper_fraction(x, y, z):
    frac_check = y/z
    closest_frac = 0
    frac_diff = frac_check - closest_frac
    closest_n = 1
    jump = 1
    for d in range(1, x+1):
        if d % 2 == 0:
            jump = 2
        else:
            jump = 1
        for n in range(closest_n, d, jump):
            frac = n / d
            if frac >= frac_check:
                break
            check = frac_check - frac
            if check < frac_diff:
                closest_frac = frac
                closest_ratio = (n, d)
                closest_n = n
                frac_diff = check
    print (closest_frac)
    return closest_ratio



print (proper_fraction(1000000, 3, 7))
#Project Euler Question 71 #By listing the set of reduced proper fractions for d ≤ 1,000,000 in ascending order of size, #find the numerator of the fraction immediately to the left of 3/7.