Truncatable primes: Difference between revisions
Content deleted Content added
→{{header|Haskell}}: added alternate solution |
|||
Line 73:
Left truncatable 998443
Right truncatable 739399</lang>
Interpretation of the J contribution:
<lang haskell>digits = [1..9] :: [Integer]
smallPrimes = filter isPrime digits
pow10 = iterate (*10) 1
mul10 = (pow10!!). length. show
righT = (+) . (10 *)
lefT = liftM2 (.) (+) ((*) . mul10)
primesTruncatable f = iterate (concatMap (filter isPrime.flip map digits. f)) smallPrimes</lang>
Output:
<lang haskell>*Main> maximum $ primesTruncatable righT !! 5
739399
*Main> maximum $ primesTruncatable lefT !! 5
998443</lang>
== Icon and Unicon ==
|