Solve 73 in Python.

main
Felix Martin 2019-08-01 21:15:14 -04:00
parent 4c93d34c26
commit d3c7dcd66a
2 changed files with 29 additions and 25 deletions

View File

@ -1,4 +1,3 @@
from collections import namedtuple
from lib_prime import primes
from functools import lru_cache
@ -14,28 +13,6 @@ def relative_primes_count_factors(n, factors):
return n // d
Fraction = namedtuple("Fraction", ["n", "d"])
# Procedures that were not actually helpful
def get_farey_series_length(f_min, f_max, d_max):
if f_min.d + f_max.d > d_max:
return 0
f_med = Fraction(f_min.n + f_max.n, f_min.d + f_max.d)
l_min = get_farey_series_length(f_min, f_med, d_max)
l_max = get_farey_series_length(f_med, f_max, d_max)
return l_min + 1 + l_max
def get_farey_series(f_min, f_max, d_max):
if f_min.d + f_max.d > d_max:
return []
f_med = Fraction(f_min.n + f_max.n, f_min.d + f_max.d)
l_min = get_farey_series(f_min, f_med, d_max)
l_max = get_farey_series(f_med, f_max, d_max)
return l_min + [f_med] + l_max
def prime_factors_unique(n, primes_list, primes_set):
if n in primes_set:
return [n]

View File

@ -1,8 +1,35 @@
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():
return 0
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() == 0)
assert(euler_073() == 7295372)