Last active
January 12, 2021 09:07
-
-
Save jeffagit-anto/ddfd95a0e49e31c66d8d9dab58b5ab7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://repl.it/languages/haskell -- Happy new year 2021 !