Skip to content

Instantly share code, notes, and snippets.

@rileypeterson
Created August 21, 2020 03:49
Show Gist options
  • Save rileypeterson/7bcba7ed43320a924ee127f8fcc088ed to your computer and use it in GitHub Desktop.
Save rileypeterson/7bcba7ed43320a924ee127f8fcc088ed to your computer and use it in GitHub Desktop.
Left truncatable primes
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