EKG sequence convergence: Difference between revisions
→{{header|Haskell}}: Suggested edit (OP may prefer to revert): applied hlint, hindent, specified imports, signatures
(→{{header|Haskell}}: Suggested edit (OP may prefer to revert): applied hlint, hindent, specified imports, signatures) |
|||
Line 254:
=={{header|Haskell}}==
<lang Haskell>import Data.List (findIndex, isPrefixOf, tails)
import Data.
seqEKGRec :: Int -> Int -> [Int] -> [Int]
seqEKG_rec k (n - 1)▼
seqEKGRec
([head (filter (\i -> (notElem i l) && ((gcd h i) > 1)) [2..])] ++ l) ▼
k
seqEKG
seqEKG k n = reverse (seqEKGRec k n [])
main :: IO ()
main = mapM_ (\x -> (putStr "EKG (" >> (putStr . show $ x) >> putStr ") is " >> print (seqEKG x 20)))▼
main =
mapM_
(\x ->
▲
print (seqEKG x 20))
[2, 5, 7, 9, 10] >>
print
((+ 1) $
(tails (zipWith (\x y -> (x==y)) (seqEKG 7 80) (seqEKG 5 80))))▼
fromJust $
findIndex
(isPrefixOf (replicate 20 True))
{{out}}
<pre>EKG (2) is [1,2,4,6,3,9,12,8,10,5,15,18,14,7,21,24,16,20,22,11]▼
▲EKG (2) is [1,2,4,6,3,9,12,8,10,5,15,18,14,7,21,24,16,20,22,11]
EKG (5) is [1,5,10,2,4,6,3,9,12,8,14,7,21,15,18,16,20,22,11,33]
EKG (7) is [1,7,14,2,4,6,3,9,12,8,10,5,15,18,16,20,22,11,33,21]
EKG (9) is [1,9,3,6,2,4,8,10,5,15,12,14,7,21,18,16,20,22,11,33]
EKG (10) is [1,10,2,4,6,3,9,12,8,14,7,21,15,5,20,16,18,22,11,33]
EKG(5) and EKG(7) converge at 21</pre>
=={{header|J}}==
|