diff options
| -rwxr-xr-x | challenge-110/stuart-little/haskell/ch-1.hs | 26 | ||||
| -rwxr-xr-x | challenge-110/stuart-little/haskell/ch-2.hs | 25 |
2 files changed, 51 insertions, 0 deletions
diff --git a/challenge-110/stuart-little/haskell/ch-1.hs b/challenge-110/stuart-little/haskell/ch-1.hs new file mode 100755 index 0000000000..cbc2aa1f60 --- /dev/null +++ b/challenge-110/stuart-little/haskell/ch-1.hs @@ -0,0 +1,26 @@ +#!/usr/bin/env runghc + +{-- +run <script> <path-to-file or nothing> +defaults to challenge sample if no file is entered +--} + +import Text.Regex.PCRE ((=~),getAllTextMatches) +import System.Environment (getArgs) + +defData :: String +defData = "0044 1148820341\n+44 1148820341\n44-11-4882-0341\n(44) 1148820341\n00 1148820341" + +dt :: IO String +dt = do + args <- getArgs + if (null args) then return defData else readFile $ head args + +rx :: String +rx = "(\\+\\d{2}|\\(\\d{2}\\)|\\d{4})\\s+\\d{10}" + +getAllRx :: String -> [String] +getAllRx s = getAllTextMatches $ s =~ rx :: [String] + +main :: IO () +main = dt >>= (putStrLn . unlines . getAllRx) diff --git a/challenge-110/stuart-little/haskell/ch-2.hs b/challenge-110/stuart-little/haskell/ch-2.hs new file mode 100755 index 0000000000..3619b9a75b --- /dev/null +++ b/challenge-110/stuart-little/haskell/ch-2.hs @@ -0,0 +1,25 @@ +#!/usr/bin/env runghc + +{-- +run <script> <path-to-file or nothing> +defaults to challenge sample if no file is entered +--} + +import Control.Monad (liftM) +import Data.List (intercalate,transpose) +import Data.List.Split (splitOn) +import System.Environment (getArgs) + +defData :: String +defData = "name,age,sex\nMohammad,45,m\nJoe,20,m\nJulie,35,f\nCristina,10,f" + +dt :: IO String +dt = do + args <- getArgs + if (null args) then return defData else readFile $ head args + +trnsp :: String -> String +trnsp = unlines . map (intercalate ",") . transpose . map (splitOn ",") . lines + +main :: IO () +main = (liftM trnsp) dt >>= putStrLn |
