Largest difference between adjacent primes: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
Line 418: | Line 418: | ||
290 R = P2 - P |
290 R = P2 - P |
||
300 RETURN</syntaxhighlight> |
300 RETURN</syntaxhighlight> |
||
=={{header|Haskell}}== |
|||
<syntaxhighlight lang="haskell">import Data.List.Split ( divvy ) |
|||
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 |
|||
solution :: Int |
|||
solution = maximum $ map (\li -> last li - head li ) $ divvy 2 1 $ filter |
|||
isPrime [1..999999] |
|||
main :: IO ( ) |
|||
main = do |
|||
print solution</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
114 |
|||
</pre> |
|||
=={{header|J}}== |
=={{header|J}}== |