Skip to content

Instantly share code, notes, and snippets.

@mjs2600
Created August 12, 2013 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjs2600/6210787 to your computer and use it in GitHub Desktop.
Save mjs2600/6210787 to your computer and use it in GitHub Desktop.
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