Adopted new convention from template

This commit is contained in:
David Doblas Jiménez 2022-10-02 18:50:24 +02:00
parent 8e85140d06
commit e8d85bdd0e

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python3 #!/usr/bin/env python
""" """
Created on 24 Sep 2021 Created on 24 Sep 2021
@ -9,7 +9,7 @@ Solution for problem 51 of Project Euler
https://projecteuler.net/problem=51 https://projecteuler.net/problem=51
""" """
from utils import timeit, list_primes, is_prime from utils import is_prime, list_primes, timeit
@timeit("Problem 51") @timeit("Problem 51")
@ -18,17 +18,18 @@ def compute():
By replacing the 1st digit of the 2-digit number *3, it turns out that By replacing the 1st digit of the 2-digit number *3, it turns out that
six of the nine possible values: 13, 23, 43, 53, 73, and 83, are all prime. six of the nine possible values: 13, 23, 43, 53, 73, and 83, are all prime.
By replacing the 3rd and 4th digits of 56**3 with the same digit, this 5-digit By replacing the 3rd and 4th digits of 56**3 with the same digit, this
number is the first example having seven primes among the ten generated numbers, 5-digit number is the first example having seven primes among the ten
yielding the family: generated numbers, yielding the family:
56003, 56113, 56333, 56443, 56663, 56773, and 56993. 56003, 56113, 56333, 56443, 56663, 56773, and 56993.
Consequently 56003, being the first member of this family, is the smallest prime Consequently 56003, being the first member of this family, is the smallest
with this property. prime with this property.
Find the smallest prime which, by replacing part of the number (not necessarily Find the smallest prime which, by replacing part of the number (not
adjacent digits) with the same digit, is part of an eight prime value family. necessarily adjacent digits) with the same digit, is part of an eight prime
value family.
""" """
primes = sorted(set(list_primes(1_000_000)) - set(list_primes(57_000))) primes = sorted(set(list_primes(1_000_000)) - set(list_primes(57_000)))
@ -49,6 +50,7 @@ def compute():
p = str(p) p = str(p)
if p.count(d) == 3 and p[-1] != d: if p.count(d) == 3 and p[-1] != d:
digits[d].append(p) digits[d].append(p)
for d in {"0", "1", "2"}: for d in {"0", "1", "2"}:
for p in digits[d]: for p in digits[d]:
res = 0 res = 0
@ -65,5 +67,4 @@ def compute():
if __name__ == "__main__": if __name__ == "__main__":
print(f"Result for Problem 51 is {compute()}")
print(f"Result for Problem 51: {compute()}")