Skip to content

Instantly share code, notes, and snippets.

@jeffagit-anto
Last active January 12, 2021 09:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffagit-anto/ddfd95a0e49e31c66d8d9dab58b5ab7b to your computer and use it in GitHub Desktop.
Save jeffagit-anto/ddfd95a0e49e31c66d8d9dab58b5ab7b to your computer and use it in GitHub Desktop.
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
Copy link
Author

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