Compare commits

...

4 Commits

Author SHA1 Message Date
a1fa273624 More pythonic 2026-04-18 15:54:59 +02:00
cf417eaca2 Get rid of auxiliary function 2026-04-18 15:52:12 +02:00
605c9c7f7f More pythonic 2026-04-18 15:31:40 +02:00
e6ed590b73 Use function from utils 2026-04-18 15:30:48 +02:00
4 changed files with 7 additions and 18 deletions

View File

@@ -29,11 +29,10 @@ def compute():
"""
ans = set()
pandigital = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
pandigital = [str(number) for number in range(1, 10)]
for x in range(1, 100):
for y in range(100, 10_000):
# product = x * y
if sorted(str(x) + str(y) + str(x * y)) == pandigital:
ans.add(x * y)

View File

@@ -9,11 +9,7 @@ Solution for problem 036 of Project Euler
https://projecteuler.net/problem=36
"""
from project_euler_python.utils import timeit
def is_palidrome(num):
return str(num) == str(num)[::-1]
from project_euler_python.utils import is_palindrome, timeit
@timeit("Problem 036")
@@ -28,7 +24,7 @@ def compute():
ans = 0
for i in range(1, 1_000_001, 2):
if is_palidrome(i) and is_palidrome(bin(i)[2:]):
if is_palindrome(i) and is_palindrome(bin(i)[2:]):
ans += i
return ans

View File

@@ -12,14 +12,6 @@ https://projecteuler.net/problem=41
from project_euler_python.utils import is_prime, timeit
def is_pandigital(number):
number = sorted(str(number))
check = [str(i) for i in range(1, len(number) + 1)]
if number == check:
return True
return False
@timeit("Problem 041")
def compute():
"""
@@ -30,8 +22,10 @@ def compute():
What is the largest n-digit pandigital prime that exists?
"""
pandigital = [str(number) for number in range(1, 10)]
for ans in range(7654321, 1, -1):
if is_pandigital(ans):
if sorted(str(ans)) == pandigital[: len(str(ans))]:
if is_prime(ans):
return ans

View File

@@ -36,7 +36,7 @@ def compute():
"""
ans = []
pandigital = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
pandigital = [str(number) for number in range(1, 10)]
for n in permutations(pandigital):
n_ = "".join(n)