Solve problem 92
This commit is contained in:
29
python/e092.py
Normal file
29
python/e092.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
from functools import cache
|
||||||
|
|
||||||
|
|
||||||
|
def euler_092():
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
square_dict = {str(i): i * i for i in range(10)}
|
||||||
|
square_lookup = lambda s: square_dict[s]
|
||||||
|
|
||||||
|
@cache
|
||||||
|
def number_chain(n):
|
||||||
|
if n == 1 or n == 89:
|
||||||
|
return n
|
||||||
|
squared_digits = map(square_lookup, str(n))
|
||||||
|
new_n = sum(squared_digits)
|
||||||
|
n = number_chain(new_n)
|
||||||
|
return n
|
||||||
|
|
||||||
|
for n in range(1, 10**7 + 1):
|
||||||
|
if number_chain(n) == 89:
|
||||||
|
count += 1
|
||||||
|
return count
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
solution = euler_092()
|
||||||
|
print("e092.py: " + str(solution))
|
||||||
|
assert(solution == 8581146)
|
||||||
|
|
||||||
24
python/e099.py
Normal file
24
python/e099.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
|
||||||
|
# def lower_upper_bound(a, b):
|
||||||
|
# print(a, b)
|
||||||
|
# return 0
|
||||||
|
|
||||||
|
|
||||||
|
def euler_099():
|
||||||
|
with open("../txt/EulerProblem099.txt", "r") as f:
|
||||||
|
pairs = [(int(s[0]), int(s[1]), i)
|
||||||
|
for i, line in enumerate(f.readlines())
|
||||||
|
if (s := line.split(","))]
|
||||||
|
|
||||||
|
# pairs.sort()
|
||||||
|
|
||||||
|
print(pairs[:2])
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
solution = euler_099()
|
||||||
|
print("e099.py: " + str(solution))
|
||||||
|
assert(solution == 0)
|
||||||
Reference in New Issue
Block a user