Sum of square and cube digits of an integer are primes: Difference between revisions

Content added Content deleted
(Added Arturo implementation)
Line 367: Line 367:
<lang haskell>import Data.Bifunctor (first)
<lang haskell>import Data.Bifunctor (first)
import Data.Numbers.Primes (isPrime)
import Data.Numbers.Primes (isPrime)

---- SQUARE AND CUBE BOTH HAVE PRIME DECIMAL DIGIT SUMS --


p :: Int -> Bool
p :: Int -> Bool
Line 372: Line 374:
((&&) . primeDigitSum . (^ 2))
((&&) . primeDigitSum . (^ 2))
<*> (primeDigitSum . (^ 3))
<*> (primeDigitSum . (^ 3))



--------------------------- TEST -------------------------
--------------------------- TEST -------------------------
main :: IO ()
main :: IO ()
main = print $ filter p [2 .. 99]
main = print $ filter p [2 .. 99]



------------------------- GENERIC ------------------------
------------------------- GENERIC ------------------------
Line 387: Line 387:
where
where
go 0 = 0
go 0 = 0
go n = uncurry (+) (first go $ quotRem n base)</lang>
go n = (uncurry (+) . first go) $ quotRem n base</lang>
{{Out}}
{{Out}}
<pre>[16,17,25,28,34,37,47,52,64]</pre>
<pre>[16,17,25,28,34,37,47,52,64]</pre>