Add documentation to 75.\nAdd solutions to 75 and 76.\nAdd templates till problem 85.

This commit is contained in:
2019-08-15 23:26:47 -04:00
parent d9e31d69cf
commit 824f3a3a8c
12 changed files with 95 additions and 5 deletions

View File

@@ -95,6 +95,22 @@ def dicksons_method_efficient(r):
def euler_075():
"""
We are using Dickson's method to get all Pythagorean triples. The
challenge is that this method requires finding the divisors for a
given r. To make it more efficient we stop iterating after the
perimeter exceeds the threshold L_max for any given r.
In addition we found a r_max of 258000 empirically.
This runs for 15 minutes with cpython and in under 5 minutes in pypy.
It would have been better to use a generator function that finds native
solutions and then extrapolate with factors k in range(2, 1500000)
while L < L_max.
https://en.wikipedia.org/wiki/Formulas_for_generating_Pythagorean_triples#Dickson's_method
XXX: Can be strongly optimized.
"""
r_max = 258000
perimeter_counts = {}
@@ -116,4 +132,4 @@ def euler_075():
if __name__ == "__main__":
print("e075.py: " + str(euler_075()))
# assert(euler_075() == 0)
assert(euler_075() == 161667)