euler/python/e073.py

36 lines
862 B
Python
Raw Normal View History

2019-07-21 20:13:28 +02:00
2019-08-02 03:15:14 +02:00
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
2019-07-21 20:13:28 +02:00
def euler_073():
2019-08-02 03:15:14 +02:00
d_max = 12000
s = get_farey_series_length(2, 3, d_max)
return s
2019-07-21 20:13:28 +02:00
if __name__ == "__main__":
print("e073.py: " + str(euler_073()))
2019-08-02 03:15:14 +02:00
assert(euler_073() == 7295372)