From e8d85bdd0efa5a5bf8bdc5b2ad1835ce82638638 Mon Sep 17 00:00:00 2001 From: daviddoji Date: Sun, 2 Oct 2022 18:50:24 +0200 Subject: [PATCH] Adopted new convention from template --- src/Python/Problem051.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Python/Problem051.py b/src/Python/Problem051.py index bdcfa58..8dc554b 100644 --- a/src/Python/Problem051.py +++ b/src/Python/Problem051.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python """ Created on 24 Sep 2021 @@ -9,7 +9,7 @@ Solution for problem 51 of Project Euler https://projecteuler.net/problem=51 """ -from utils import timeit, list_primes, is_prime +from utils import is_prime, list_primes, timeit @timeit("Problem 51") @@ -18,17 +18,18 @@ def compute(): 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. - By replacing the 3rd and 4th digits of 56**3 with the same digit, this 5-digit - number is the first example having seven primes among the ten generated numbers, - yielding the family: + By replacing the 3rd and 4th digits of 56**3 with the same digit, this + 5-digit number is the first example having seven primes among the ten + generated numbers, yielding the family: 56003, 56113, 56333, 56443, 56663, 56773, and 56993. - Consequently 56003, being the first member of this family, is the smallest prime - with this property. + Consequently 56003, being the first member of this family, is the smallest + prime with this property. - Find the smallest prime which, by replacing part of the number (not necessarily - adjacent digits) with the same digit, is part of an eight prime value family. + Find the smallest prime which, by replacing part of the number (not + 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))) @@ -49,6 +50,7 @@ def compute(): p = str(p) if p.count(d) == 3 and p[-1] != d: digits[d].append(p) + for d in {"0", "1", "2"}: for p in digits[d]: res = 0 @@ -65,5 +67,4 @@ def compute(): if __name__ == "__main__": - - print(f"Result for Problem 51: {compute()}") + print(f"Result for Problem 51 is {compute()}")