Largest difference between adjacent primes: Difference between revisions

Added Easylang
No edit summary
(Added Easylang)
 
(One intermediate revision by one other user not shown)
Line 283:
</pre>
 
 
=={{header|EasyLang}}==
<syntaxhighlight>
fastfunc isprim num .
i = 2
while i <= sqrt num
if num mod i = 0
return 0
.
i += 1
.
return 1
.
fastfunc nextprim prim .
repeat
prim += 1
until isprim prim = 1
.
return prim
.
prim = 2
repeat
prev = prim
prim = nextprim prim
until prim > 1e6
max = higher max (prim - prev)
.
print max
</syntaxhighlight>
{{out}}
<pre>
114
</pre>
 
=={{header|F_Sharp|F#}}==
Line 418 ⟶ 451:
290 R = P2 - P
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}}==
1,985

edits