Neighbour primes: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
No edit summary |
||
Line 510: | Line 510: | ||
Found 20 such primes. |
Found 20 such primes. |
||
</pre> |
|||
=={{header|Haskell}}== |
|||
<syntaxhighlight lang="haskell"> |
|||
import Data.List.Split ( divvy ) |
|||
isPrime :: Int -> Bool |
|||
isPrime n |
|||
|n < 2 = False |
|||
|otherwise = null $ filter (\i -> mod n i == 0 ) [2 .. root] |
|||
where |
|||
root :: Int |
|||
root = floor $ sqrt $ fromIntegral n |
|||
solution :: [Int] |
|||
solution = map head $ filter (\li -> isPrime ((head li * last li) + 2 )) |
|||
$ divvy 2 1 $ filter isPrime [2..upTo] |
|||
where |
|||
upTo :: Int |
|||
upTo = head $ take 1 $ filter isPrime [500..] |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
[3,5,7,13,19,67,149,179,229,239,241,269,277,307,313,397,401,419,439,487] |
|||
</pre> |
</pre> |
||