Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
primes :: [Int]
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
pr :: [Int] -> [Int]
-- if 2 elements n & m :
pr (n:m:tail) = n*m : pr (m:tail)
-- 1. calculate their product --^ ^-- 2. continue with shifted list 'm:tail'
-- and 3. concatenate (:) the whole result
-- on other case : return the empty list '[]'
pr _ = []
-- notice that pr will drop its argument's last element, if any, decrementing the initial list size by 1 !
main = do putStrLn $ show (pr primes) ++ " Happy New Year!"
@jeffagit-anto

This comment has been minimized.

Copy link
Owner Author

@jeffagit-anto jeffagit-anto commented Jan 6, 2021

https://repl.it/languages/haskell -- Happy new year 2021 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment