diff options
| -rwxr-xr-x | challenge-033/stuart-little/haskell/ch-1.hs | 13 | ||||
| -rwxr-xr-x | challenge-033/stuart-little/haskell/ch-2.hs | 14 |
2 files changed, 27 insertions, 0 deletions
diff --git a/challenge-033/stuart-little/haskell/ch-1.hs b/challenge-033/stuart-little/haskell/ch-1.hs new file mode 100755 index 0000000000..b862cbe4e0 --- /dev/null +++ b/challenge-033/stuart-little/haskell/ch-1.hs @@ -0,0 +1,13 @@ +#!/usr/bin/env runghc + +-- run <script> <space-separated file paths> + +import System.Environment (getArgs,) +import Control.Monad (liftM,) +import Data.Char (toLower,) +import Data.List.Utils (countElem,) + +main = do + files <- getArgs + text <- liftM ((map toLower).concat) $ sequence $ map readFile files + mapM_ putStrLn $ map (\c-> [c] ++ ": " ++ (show $ countElem c text)) ['a'..'z'] diff --git a/challenge-033/stuart-little/haskell/ch-2.hs b/challenge-033/stuart-little/haskell/ch-2.hs new file mode 100755 index 0000000000..14979da343 --- /dev/null +++ b/challenge-033/stuart-little/haskell/ch-2.hs @@ -0,0 +1,14 @@ +#!/usr/bin/env runghc + +-- run <script> <size of the mult_table> + +import System.Environment (getArgs,) +import Control.Monad (liftM,) + +pad :: Int -> String -> String +pad nr str = (replicate ((-) nr $ length str) ' ') ++ str + +main = do + n <- liftM (read::String->Int) $ liftM head getArgs + let ln = length $ show (n*n) + mapM_ putStrLn $ map unwords $ map (\x -> map (\y -> if (y<x) then (replicate ln ' ') else (pad ln (show (x*y)))) [1..n]) [1..n] |
