Created
August 12, 2013 13:27
-
-
Save mjs2600/6210787 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
import System.Environment | |
import Data.List | |
main :: IO() | |
main = fmap factorialize getArgs >>= putStrLn | |
factorialize :: [String] -> String | |
factorialize = toStr . factorials . toIntegers | |
toIntegers :: [String] -> [Integer] | |
toIntegers = map read | |
toStr :: [Integer] -> String | |
toStr = unwords . map show | |
factorials :: [Integer] -> [Integer] | |
factorials = map factorial | |
factorial :: Integer -> Integer | |
factorial 0 = 1 | |
factorial num = factAcc [1..num] | |
factAcc :: [Integer] -> Integer | |
factAcc = foldl' (*) 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment