MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_051/sol1.py:78–110  ·  view source on GitHub ↗

Returns the solution of the problem >>> solution(2) 229399 >>> solution(3) 221311

(family_length: int = 8)

Source from the content-addressed store, hash-verified

76
77
78def solution(family_length: int = 8) -> int:
79 """
80 Returns the solution of the problem
81
82 >>> solution(2)
83 229399
84
85 >>> solution(3)
86 221311
87 """
88 numbers_checked = set()
89
90 # Filter primes with less than 3 replaceable digits
91 primes = {
92 x for x in set(prime_sieve(1_000_000)) if len(str(x)) - len(set(str(x))) >= 3
93 }
94
95 for prime in primes:
96 if prime in numbers_checked:
97 continue
98
99 replacements = digit_replacements(prime)
100
101 for family in replacements:
102 numbers_checked.update(family)
103 primes_in_family = primes.intersection(family)
104
105 if len(primes_in_family) != family_length:
106 continue
107
108 return min(primes_in_family)
109
110 return -1
111
112
113if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 4

digit_replacementsFunction · 0.85
intersectionMethod · 0.80
prime_sieveFunction · 0.70
updateMethod · 0.45

Tested by

no test coverage detected