Brute force

To solve the problem of finding truncatable primes, we will use Python's slicing again to check whether the left and right slices of a number are prime. Using the all function, we can check both slices at once efficiently.

From solution1.py:

def is_truncatable_prime(n):
    return all(isprime(int(n[i:])) and isprime(int(n[:i])) for i in range(1, len(n)))

Since the problem states that there are only eleven primes, we don't need to set an upper bound for our iteration. We can use itertools.count to make the code more concise.

From solution1.py:

def truncatable_primes():
    res = []
    for i in itertools.count(10):
        if isprime(i) and is_truncatable_prime(str(i)):
            res.append(i)
            if len(res) == 11:
                return sum(res)