Unified numbers and output
This commit is contained in:
parent
220a742b6b
commit
4ffdf12329
@ -5,14 +5,14 @@ Created on 24 Sep 2021
|
||||
@author: David Doblas Jiménez
|
||||
@email: daviddoji@pm.me
|
||||
|
||||
Solution for problem 51 of Project Euler
|
||||
Solution for problem 051 of Project Euler
|
||||
https://projecteuler.net/problem=51
|
||||
"""
|
||||
|
||||
from utils import is_prime, list_primes, timeit
|
||||
|
||||
|
||||
@timeit("Problem 51")
|
||||
@timeit("Problem 051")
|
||||
def compute():
|
||||
"""
|
||||
By replacing the 1st digit of the 2-digit number *3, it turns out that
|
||||
@ -67,4 +67,4 @@ def compute():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"Result for Problem 51 is {compute()}")
|
||||
print(f"Result for Problem 051: {compute()}")
|
||||
|
||||
@ -5,14 +5,14 @@ Created on 26 Sep 2021
|
||||
@author: David Doblas Jiménez
|
||||
@email: daviddoji@pm.me
|
||||
|
||||
Solution for problem 52 of Project Euler
|
||||
Solution for problem 052 of Project Euler
|
||||
https://projecteuler.net/problem=52
|
||||
"""
|
||||
|
||||
from utils import timeit
|
||||
|
||||
|
||||
@timeit("Problem 52")
|
||||
@timeit("Problem 052")
|
||||
def compute():
|
||||
"""
|
||||
It can be seen that the number, 125874, and its double, 251748,
|
||||
@ -35,4 +35,4 @@ def compute():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"Result for Problem 52 is {compute()}")
|
||||
print(f"Result for Problem 052: {compute()}")
|
||||
|
||||
@ -5,7 +5,7 @@ Created on 26 Sep 2021
|
||||
@author: David Doblas Jiménez
|
||||
@email: daviddoji@pm.me
|
||||
|
||||
Solution for problem 53 of Project Euler
|
||||
Solution for problem 053 of Project Euler
|
||||
https://projecteuler.net/problem=53
|
||||
"""
|
||||
|
||||
@ -14,7 +14,7 @@ from math import comb
|
||||
from utils import timeit
|
||||
|
||||
|
||||
@timeit("Problem 53")
|
||||
@timeit("Problem 053")
|
||||
def compute():
|
||||
"""
|
||||
There are exactly ten ways of selecting three from five, 12345:
|
||||
@ -42,4 +42,4 @@ def compute():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"Result for Problem 53 is {compute()}")
|
||||
print(f"Result for Problem 053: {compute()}")
|
||||
|
||||
@ -5,7 +5,7 @@ Created on 27 Sep 2021
|
||||
@author: David Doblas Jiménez
|
||||
@email: daviddoji@pm.me
|
||||
|
||||
Solution for problem 54 of Project Euler
|
||||
Solution for problem 054 of Project Euler
|
||||
https://projecteuler.net/problem=54
|
||||
"""
|
||||
|
||||
@ -72,7 +72,7 @@ def royal_flush(str_hand: list) -> bool:
|
||||
return flush(str_hand) and list(range(14, 9, -1)) == to_numerical(str_hand)
|
||||
|
||||
|
||||
@timeit("Problem 54")
|
||||
@timeit("Problem 054")
|
||||
def compute():
|
||||
"""
|
||||
In the card game poker, a hand consists of five cards and are ranked,
|
||||
@ -129,7 +129,7 @@ def compute():
|
||||
replace_map = {"T": 10, "J": 11, "Q": 12, "K": 13, "A": 14}
|
||||
score = [0, 0]
|
||||
|
||||
file = Path("../files/Problem54.txt")
|
||||
file = Path("files/Problem54.txt")
|
||||
for line in open(file, "r").read().splitlines():
|
||||
line = replace_values_in_string(line, replace_map).split()
|
||||
hands = line[:5], line[5:]
|
||||
@ -160,4 +160,4 @@ def compute():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"Result for Problem 54 is {compute()}")
|
||||
print(f"Result for Problem 054: {compute()}")
|
||||
|
||||
@ -5,14 +5,14 @@ Created on 02 Oct 2021
|
||||
@author: David Doblas Jiménez
|
||||
@email: daviddoji@pm.me
|
||||
|
||||
Solution for problem 55 of Project Euler
|
||||
Solution for problem 055 of Project Euler
|
||||
https://projecteuler.net/problem=55
|
||||
"""
|
||||
|
||||
from utils import is_palindrome, timeit
|
||||
|
||||
|
||||
@timeit("Problem 55")
|
||||
@timeit("Problem 055")
|
||||
def compute():
|
||||
"""
|
||||
If we take 47, reverse and add, 47 + 74 = 121, which is palindromic.
|
||||
@ -63,4 +63,4 @@ def compute():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"Result for Problem 55 is {compute()}")
|
||||
print(f"Result for Problem 055: {compute()}")
|
||||
|
||||
@ -5,14 +5,14 @@ Created on 07 Oct 2021
|
||||
@author: David Doblas Jiménez
|
||||
@email: daviddoji@pm.me
|
||||
|
||||
Solution for problem 56 of Project Euler
|
||||
Solution for problem 056 of Project Euler
|
||||
https://projecteuler.net/problem=56
|
||||
"""
|
||||
|
||||
from utils import timeit
|
||||
|
||||
|
||||
@timeit("Problem 56")
|
||||
@timeit("Problem 056")
|
||||
def compute():
|
||||
"""
|
||||
A googol (10^100) is a massive number: one followed by one-hundred zeros;
|
||||
@ -34,4 +34,4 @@ def compute():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"Result for Problem 56 is {compute()}")
|
||||
print(f"Result for Problem 056: {compute()}")
|
||||
|
||||
@ -5,7 +5,7 @@ Created on 09 Oct 2021
|
||||
@author: David Doblas Jiménez
|
||||
@email: daviddoji@pm.me
|
||||
|
||||
Solution for problem 57 of Project Euler
|
||||
Solution for problem 057 of Project Euler
|
||||
https://projecteuler.net/problem=57
|
||||
"""
|
||||
|
||||
@ -14,7 +14,7 @@ from fractions import Fraction
|
||||
from utils import timeit
|
||||
|
||||
|
||||
@timeit("Problem 57")
|
||||
@timeit("Problem 057")
|
||||
def compute():
|
||||
"""
|
||||
It is possible to show that the square root of two can be expressed
|
||||
@ -47,4 +47,4 @@ def compute():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"Result for Problem 57 is {compute()}")
|
||||
print(f"Result for Problem 057: {compute()}")
|
||||
|
||||
@ -5,14 +5,14 @@ Created on 10 Oct 2021
|
||||
@author: David Doblas Jiménez
|
||||
@email: daviddoji@pm.me
|
||||
|
||||
Solution for problem 58 of Project Euler
|
||||
Solution for problem 058 of Project Euler
|
||||
https://projecteuler.net/problem=58
|
||||
"""
|
||||
|
||||
from utils import is_prime, timeit
|
||||
|
||||
|
||||
@timeit("Problem 58")
|
||||
@timeit("Problem 058")
|
||||
def compute():
|
||||
"""
|
||||
Starting with 1 and spiralling anticlockwise in the following way,
|
||||
@ -52,4 +52,4 @@ def compute():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"Result for Problem 58 is {compute()}")
|
||||
print(f"Result for Problem 058: {compute()}")
|
||||
|
||||
@ -5,7 +5,7 @@ Created on 13 Oct 2021
|
||||
@author: David Doblas Jiménez
|
||||
@email: daviddoji@pm.me
|
||||
|
||||
Solution for problem 59 of Project Euler
|
||||
Solution for problem 059 of Project Euler
|
||||
https://projecteuler.net/problem=59
|
||||
"""
|
||||
|
||||
@ -15,7 +15,7 @@ from string import ascii_lowercase
|
||||
from utils import timeit
|
||||
|
||||
|
||||
@timeit("Problem 59")
|
||||
@timeit("Problem 059")
|
||||
def compute():
|
||||
"""
|
||||
Each character on a computer is assigned a unique code and the preferred
|
||||
@ -46,7 +46,7 @@ def compute():
|
||||
values in the original text.
|
||||
"""
|
||||
|
||||
with open("../files/Problem59.txt", "r") as f:
|
||||
with open("files/Problem59.txt", "r") as f:
|
||||
encrypted = [int(char) for char in f.read().split(",")]
|
||||
|
||||
plain_text = len(encrypted) // 3
|
||||
@ -61,4 +61,4 @@ def compute():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"Result for Problem 59 is {compute()}")
|
||||
print(f"Result for Problem 059: {compute()}")
|
||||
|
||||
@ -5,7 +5,7 @@ Created on 04 Dic 2021
|
||||
@author: David Doblas Jiménez
|
||||
@email: daviddoji@pm.me
|
||||
|
||||
Solution for problem 60 of Project Euler
|
||||
Solution for problem 060 of Project Euler
|
||||
https://projecteuler.net/problem=60
|
||||
"""
|
||||
|
||||
@ -22,7 +22,6 @@ def solve_backtrack(max_chain_length, chain):
|
||||
return chain
|
||||
solve_backtrack(max_chain_length, chain)
|
||||
chain.pop()
|
||||
|
||||
return chain
|
||||
|
||||
|
||||
@ -32,11 +31,10 @@ def is_concatenable(chain, candidate):
|
||||
return False
|
||||
if not is_prime(int(str(candidate) + str(n))):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@timeit("Problem 60")
|
||||
@timeit("Problem 060")
|
||||
def compute():
|
||||
"""
|
||||
The primes 3, 7, 109, and 673, are quite remarkable. By taking any two
|
||||
@ -50,8 +48,9 @@ def compute():
|
||||
"""
|
||||
|
||||
ans = solve_backtrack(5, [])
|
||||
|
||||
return sum(ans)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"Result for Problem 60 is {compute()}")
|
||||
print(f"Result for Problem 060: {compute()}")
|
||||
|
||||
@ -5,7 +5,7 @@ Created on 16 Jul 2022
|
||||
@author: David Doblas Jiménez
|
||||
@email: daviddoji@pm.me
|
||||
|
||||
Solution for problem 61 of Project Euler
|
||||
Solution for problem 061 of Project Euler
|
||||
https://projecteuler.net/problem=61
|
||||
"""
|
||||
|
||||
@ -29,7 +29,7 @@ eligibles: dict[int, list[str]] = {
|
||||
}
|
||||
|
||||
|
||||
@timeit("Problem 61")
|
||||
@timeit("Problem 061")
|
||||
def compute():
|
||||
"""
|
||||
Triangle, square, pentagonal, hexagonal, heptagonal, and octagonal numbers
|
||||
@ -76,9 +76,8 @@ def compute():
|
||||
eligibles.get(perm[5]),
|
||||
):
|
||||
ans.append([a, b, c, d, e, f])
|
||||
|
||||
return sum(map(int, ans[0]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"Result for Problem 61 is {compute()}")
|
||||
print(f"Result for Problem 061: {compute()}")
|
||||
|
||||
@ -5,7 +5,7 @@ Created on 25 Jul 2022
|
||||
@author: David Doblas Jiménez
|
||||
@email: daviddoji@pm.me
|
||||
|
||||
Solution for problem 62 of Project Euler
|
||||
Solution for problem 062 of Project Euler
|
||||
https://projecteuler.net/problem=62
|
||||
"""
|
||||
|
||||
@ -14,7 +14,7 @@ from collections import defaultdict
|
||||
from utils import timeit
|
||||
|
||||
|
||||
@timeit("Problem 62")
|
||||
@timeit("Problem 062")
|
||||
def compute():
|
||||
"""
|
||||
The cube, 41063625 (345^3), can be permuted to produce two other cubes:
|
||||
@ -31,9 +31,8 @@ def compute():
|
||||
cube_str = "".join(sorted(list(str(number**3))))
|
||||
cubes[cube_str].append(number**3)
|
||||
if len(cubes[cube_str]) == 5:
|
||||
|
||||
return min(cubes[cube_str])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"Result for Problem 62 is {compute()}")
|
||||
print(f"Result for Problem 062: {compute()}")
|
||||
|
||||
@ -5,14 +5,14 @@ Created on 05 Aug 2022
|
||||
@author: David Doblas Jiménez
|
||||
@email: daviddoji@pm.me
|
||||
|
||||
Solution for problem 63 of Project Euler
|
||||
Solution for problem 063 of Project Euler
|
||||
https://projecteuler.net/problem=63
|
||||
"""
|
||||
|
||||
from utils import timeit
|
||||
|
||||
|
||||
@timeit("Problem 63")
|
||||
@timeit("Problem 063")
|
||||
def compute():
|
||||
"""
|
||||
The 5-digit number, 16807=7^5, is also a fifth power. Similarly, the
|
||||
@ -20,6 +20,7 @@ def compute():
|
||||
|
||||
How many n-digit positive integers exist which are also an nth power?
|
||||
"""
|
||||
|
||||
ans = 0
|
||||
# no need to go higher than 10, because 10**2 = 100
|
||||
for number in range(1, 10):
|
||||
@ -31,4 +32,4 @@ def compute():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"Result for Problem 63 is {compute()}")
|
||||
print(f"Result for Problem 063: {compute()}")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user