Solve problem 347 and some reformatting.
This commit is contained in:
@@ -52,4 +52,3 @@ if __name__ == "__main__":
|
|||||||
solution = euler_203()
|
solution = euler_203()
|
||||||
print("e203.py: " + str(solution))
|
print("e203.py: " + str(solution))
|
||||||
assert solution == 34029210557338
|
assert solution == 34029210557338
|
||||||
|
|
||||||
|
|||||||
@@ -35,4 +35,4 @@ def euler_204():
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
solution = euler_204()
|
solution = euler_204()
|
||||||
print("e204.py: " + str(solution))
|
print("e204.py: " + str(solution))
|
||||||
assert(solution == 2944730)
|
assert solution == 2944730
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ def euler_205():
|
|||||||
for six_value, six_count in get_item_counts(scores_six).items():
|
for six_value, six_count in get_item_counts(scores_six).items():
|
||||||
if four_value > six_value:
|
if four_value > six_value:
|
||||||
current_six_count += six_count
|
current_six_count += six_count
|
||||||
four_won_count += (four_count * current_six_count)
|
four_won_count += four_count * current_six_count
|
||||||
|
|
||||||
p = four_won_count / all_combinations
|
p = four_won_count / all_combinations
|
||||||
return f"{round(p, 7)}"
|
return f"{round(p, 7)}"
|
||||||
@@ -32,4 +32,3 @@ if __name__ == "__main__":
|
|||||||
solution = euler_205()
|
solution = euler_205()
|
||||||
print("e205.py: " + str(solution))
|
print("e205.py: " + str(solution))
|
||||||
# assert(solution == 0)
|
# assert(solution == 0)
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,13 @@ import math
|
|||||||
|
|
||||||
|
|
||||||
def is_square(apositiveint):
|
def is_square(apositiveint):
|
||||||
""" From: https://stackoverflow.com/a/2489519 """
|
"""From: https://stackoverflow.com/a/2489519"""
|
||||||
x = apositiveint // 2
|
x = apositiveint // 2
|
||||||
seen = set([x])
|
seen = set([x])
|
||||||
while x * x != apositiveint:
|
while x * x != apositiveint:
|
||||||
x = (x + (apositiveint // x)) // 2
|
x = (x + (apositiveint // x)) // 2
|
||||||
if x in seen: return False
|
if x in seen:
|
||||||
|
return False
|
||||||
seen.add(x)
|
seen.add(x)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ def canditates(current_value, depth):
|
|||||||
if depth <= 0:
|
if depth <= 0:
|
||||||
yield current_value
|
yield current_value
|
||||||
else:
|
else:
|
||||||
d = 10 ** depth
|
d = 10**depth
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
for new_value in canditates(current_value - i * d, depth - 2):
|
for new_value in canditates(current_value - i * d, depth - 2):
|
||||||
yield new_value
|
yield new_value
|
||||||
@@ -32,5 +33,4 @@ def euler_206():
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
solution = euler_206()
|
solution = euler_206()
|
||||||
print("e206.py: " + str(solution))
|
print("e206.py: " + str(solution))
|
||||||
assert(solution == 1389019170)
|
assert solution == 1389019170
|
||||||
|
|
||||||
|
|||||||
@@ -37,4 +37,4 @@ def euler_243():
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
solution = euler_243()
|
solution = euler_243()
|
||||||
print("e243.py: " + str(solution))
|
print("e243.py: " + str(solution))
|
||||||
assert(solution == 892371480)
|
assert solution == 892371480
|
||||||
|
|||||||
39
python/e347.py
Normal file
39
python/e347.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
from lib_prime import primes
|
||||||
|
from typing import Optional, Tuple
|
||||||
|
|
||||||
|
|
||||||
|
def s(n):
|
||||||
|
ps = primes(n)
|
||||||
|
|
||||||
|
sum = 0
|
||||||
|
for p1_index in range(len(ps)):
|
||||||
|
p1 = ps[p1_index]
|
||||||
|
for p2_index in range(p1_index + 1, len(ps)):
|
||||||
|
p2 = ps[p2_index]
|
||||||
|
if p1 * p2 > n:
|
||||||
|
break
|
||||||
|
largest: Optional[Tuple[int, int, int]] = None
|
||||||
|
p1e = 1
|
||||||
|
while p1**p1e * p2 <= n:
|
||||||
|
p2e = 1
|
||||||
|
m = p1**p1e * p2**p2e
|
||||||
|
while m <= n:
|
||||||
|
if largest is None or m > largest[2]:
|
||||||
|
largest = (p1, p2, m)
|
||||||
|
p2e += 1
|
||||||
|
m = p1**p1e * p2**p2e
|
||||||
|
p1e += 1
|
||||||
|
assert largest is not None
|
||||||
|
sum += largest[2]
|
||||||
|
return sum
|
||||||
|
|
||||||
|
|
||||||
|
def euler_347():
|
||||||
|
assert s(100) == 2262
|
||||||
|
return s(10_000_000)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
solution = euler_347()
|
||||||
|
print("e347.py: " + str(solution))
|
||||||
|
assert solution == 11109800204052
|
||||||
Reference in New Issue
Block a user