Add documentation to 75.\nAdd solutions to 75 and 76.\nAdd templates till problem 85.
This commit is contained in:
@@ -95,6 +95,22 @@ def dicksons_method_efficient(r):
|
|||||||
|
|
||||||
|
|
||||||
def euler_075():
|
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
|
r_max = 258000
|
||||||
perimeter_counts = {}
|
perimeter_counts = {}
|
||||||
|
|
||||||
@@ -116,4 +132,4 @@ def euler_075():
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("e075.py: " + str(euler_075()))
|
print("e075.py: " + str(euler_075()))
|
||||||
# assert(euler_075() == 0)
|
assert(euler_075() == 161667)
|
||||||
|
|||||||
@@ -14,8 +14,10 @@ def possible_sums(n, n_orig, d):
|
|||||||
return possible_sums(n - d, n_orig, d) + possible_sums(n, n_orig, d + 1)
|
return possible_sums(n - d, n_orig, d) + possible_sums(n, n_orig, d + 1)
|
||||||
|
|
||||||
|
|
||||||
def euler_067():
|
def euler_076():
|
||||||
return possible_sums(100, 100, 1)
|
return possible_sums(100, 100, 1)
|
||||||
|
|
||||||
|
|
||||||
print(euler_067())
|
if __name__ == "__main__":
|
||||||
|
print("e076.py: " + str(euler_076()))
|
||||||
|
assert(euler_076() == 190569291)
|
||||||
|
|||||||
8
python/e077.py
Normal file
8
python/e077.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
def euler_077():
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print("e077.py: " + str(euler_077()))
|
||||||
|
assert(euler_077() == 0)
|
||||||
8
python/e078.py
Normal file
8
python/e078.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
def euler_078():
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print("e078.py: " + str(euler_078()))
|
||||||
|
assert(euler_078() == 0)
|
||||||
8
python/e079.py
Normal file
8
python/e079.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
def euler_079():
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print("e079.py: " + str(euler_079()))
|
||||||
|
assert(euler_079() == 0)
|
||||||
8
python/e080.py
Normal file
8
python/e080.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
def euler_080():
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print("e080.py: " + str(euler_080()))
|
||||||
|
assert(euler_080() == 0)
|
||||||
8
python/e081.py
Normal file
8
python/e081.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
def euler_081():
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print("e081.py: " + str(euler_081()))
|
||||||
|
assert(euler_081() == 0)
|
||||||
8
python/e082.py
Normal file
8
python/e082.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
def euler_082():
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print("e082.py: " + str(euler_082()))
|
||||||
|
assert(euler_082() == 0)
|
||||||
8
python/e083.py
Normal file
8
python/e083.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
def euler_083():
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print("e083.py: " + str(euler_083()))
|
||||||
|
assert(euler_083() == 0)
|
||||||
8
python/e084.py
Normal file
8
python/e084.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
def euler_084():
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print("e084.py: " + str(euler_084()))
|
||||||
|
assert(euler_084() == 0)
|
||||||
8
python/e085.py
Normal file
8
python/e085.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
def euler_085():
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print("e085.py: " + str(euler_085()))
|
||||||
|
assert(euler_085() == 0)
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
FROM = 70
|
FROM = 77
|
||||||
TILL = 75
|
TILL = 85
|
||||||
|
|
||||||
template = """
|
template = """
|
||||||
def euler_XXX():
|
def euler_XXX():
|
||||||
|
|||||||
Reference in New Issue
Block a user