Nice primes: Difference between revisions

no edit summary
m (syntax highlighting fixup automation)
No edit summary
Line 870:
Same as Wren example.
</pre>
 
=={{header|Haskell}}==
<syntaxhighlight lang="haskell">
import Data.Char ( digitToInt )
 
isPrime :: Int -> Bool
isPrime n
|n == 2 = True
|n == 1 = False
|otherwise = null $ filter (\i -> mod n i == 0 ) [2 .. root]
where
root :: Int
root = floor $ sqrt $ fromIntegral n
 
digitsum :: Int -> Int
digitsum n = sum $ map digitToInt $ show n
 
findSumn :: Int -> Int
findSumn n = until ( (== 1) . length . show ) digitsum n
 
isNicePrime :: Int -> Bool
isNicePrime n = isPrime n && isPrime ( findSumn n )
 
solution :: [Int]
solution = filter isNicePrime [501..999]</syntaxhighlight>
{{out}}
<pre>
[509,547,563,569,587,599,601,617,619,641,653,659,673,677,691,709,727,743,761,797,821,839,853,857,887,907,911,929,941,947,977,983,997]
</pre>
 
 
258

edits