Created
November 18, 2013 20:26
-
-
Save nickserv/7534704 to your computer and use it in GitHub Desktop.
Haskell practice
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
divisible x y = x `mod` y == 0 | |
main = print $ sum [x | x <- [1..999], x `divisible` 3 || x `divisible` 5] |
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
factorial 1 = 1 | |
factorial n = n * factorial (n-1) | |
main = print $ factorial 5 |
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
-- |Reverses a list (top level elements only). | |
reverse2 :: [a] -> [a] | |
reverse2 [] = [] | |
reverse2 list = reverse2 (tail list) ++ [head list] | |
main = print $ reverse2 ["g", "f", "e", "d", "c", "b", "a"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment