MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / validate

Function validate

project_euler/problem_037/sol1.py:77–91  ·  view source on GitHub ↗

To optimize the approach, we will rule out the numbers above 1000, whose first or last three digits are not prime >>> validate(74679) False >>> validate(235693) False >>> validate(3797) True

(n: int)

Source from the content-addressed store, hash-verified

75
76
77def validate(n: int) -> bool:
78 """
79 To optimize the approach, we will rule out the numbers above 1000,
80 whose first or last three digits are not prime
81 >>> validate(74679)
82 False
83 >>> validate(235693)
84 False
85 >>> validate(3797)
86 True
87 """
88 return not (
89 len(str(n)) > 3
90 and (not is_prime(int(str(n)[-3:])) or not is_prime(int(str(n)[:3])))
91 )
92
93
94def compute_truncated_primes(count: int = 11) -> list[int]:

Callers 1

compute_truncated_primesFunction · 0.70

Calls 1

is_primeFunction · 0.70

Tested by

no test coverage detected