Returns the solution of the problem >>> solution(2) 229399 >>> solution(3) 221311
(family_length: int = 8)
| 76 | |
| 77 | |
| 78 | def 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 | |
| 113 | if __name__ == "__main__": |
no test coverage detected