diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-04-27 11:39:03 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-27 11:39:03 +0100 |
| commit | 77c39151cd978586279d5cbb1e6e571980a018e6 (patch) | |
| tree | 8184159271c641ad9ccef1e8aab14ad8424f7dc2 | |
| parent | 259c307f52900ae1b780187c09a2b9411df897a6 (diff) | |
| parent | 34f8e87c4350650483e85ac22e071315bf49feea (diff) | |
| download | perlweeklychallenge-club-77c39151cd978586279d5cbb1e6e571980a018e6.tar.gz perlweeklychallenge-club-77c39151cd978586279d5cbb1e6e571980a018e6.tar.bz2 perlweeklychallenge-club-77c39151cd978586279d5cbb1e6e571980a018e6.zip | |
Merge pull request #3968 from stuart-little/stuart-little_110_haskell
1st commit on 110_haskell
| -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 |
