euler/python/e073.py
2019-08-01 21:15:14 -04:00

36 lines
862 B
Python

def get_farey_series_length_recursive(d_1, d_2, d_max):
if d_1 + d_2 > d_max:
return 0
d_med = d_1 + d_2
l_min = get_farey_series_length_recursive(d_1, d_med, d_max)
l_max = get_farey_series_length_recursive(d_med, d_2, d_max)
return l_min + 1 + l_max
def get_farey_series_length(d_1, d_2, d_max):
new_pairs = [(d_1, d_2)]
s = 0
while new_pairs:
pairs = new_pairs
new_pairs = []
for d_1, d_2 in pairs:
d_new = d_1 + d_2
if d_new <= d_max:
s += 1
new_pairs.append((d_1, d_new))
new_pairs.append((d_new, d_2))
return s
def euler_073():
d_max = 12000
s = get_farey_series_length(2, 3, d_max)
return s
if __name__ == "__main__":
print("e073.py: " + str(euler_073()))
assert(euler_073() == 7295372)