28
2
As we all know, it's turtles all the way down. But is it primes all the way down too?
A number is considered a "turtle-prime" if it satisfies the following conditions:
1) It is prime.
2) It is possible to remove a single digit leaving a prime number.
3) Step 2 can be repeated until left with a single digit prime.
For example, 239
is a "turtle-prime", as it can be reduced to 23
then either 2
or 3
, both of which are prime. It also can be reduced to 29
then 2
. 151
is not a turtle prime, as it reduces to 15
(not prime), 51
(not prime), or 11
. 11
is prime, but can only reduce to 1
, which is not.
Given a positive integer, determine if it is a "turtle-prime". Your output can be in any form so long as it gives the same output for any truthy or falsey value.
Test cases:
input -> output
1 -> false
2 -> true
17 -> true
19 -> false
239 -> true
389 -> false
Scoring
This is code-golf, so the shortest answer in each language wins!
5Related – Magic Octopus Urn – 2017-07-17T16:55:29.257
@MagicOctopusUrn WOW – Keyu Gan – 2017-07-17T16:56:03.007
8Actually related – FryAmTheEggman – 2017-07-17T16:56:15.890
3Can we take input as a list of digits? – totallyhuman – 2017-07-17T17:02:18.603
@totallyhuman I don't see why not. Go for it! – Lord Farquaad – 2017-07-17T17:29:57.310
1Your conditions say that all single-digit primes are not turtle primes. Condition 2 fails: it is not possible to remove a digit and still leave a prime number, as removing the only digit leaves nothing. – hvd – 2017-07-18T20:04:48.220