Created
August 21, 2020 03:49
-
-
Save rileypeterson/7bcba7ed43320a924ee127f8fcc088ed to your computer and use it in GitHub Desktop.
Left truncatable primes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def pt(x): | |
x = int(x) | |
for i in range(2, math.floor(math.sqrt(x))): | |
if x % i == 0: | |
return False | |
return True | |
def checker(left=None, res=None): | |
l = {"1", "3", "7", "9"} | |
v = ["2", "3", "5", "7"] | |
left = left or v | |
res = res or set(v) | |
for x in left: | |
for i in l: | |
if pt(x + i): | |
res.add(x + i) | |
checker([x + i], res) | |
return sorted(list(map(int, res))) | |
checker() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment