aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchirvasitua <stuart-little@users.noreply.github.com>2021-04-26 17:04:14 -0400
committerchirvasitua <stuart-little@users.noreply.github.com>2021-04-26 17:04:14 -0400
commit34f8e87c4350650483e85ac22e071315bf49feea (patch)
tree5a7dcf27e742370f6b6bd451706ee60b6c4c6a11
parent32b7f3041862a27fd0a89328b57879750269b560 (diff)
downloadperlweeklychallenge-club-34f8e87c4350650483e85ac22e071315bf49feea.tar.gz
perlweeklychallenge-club-34f8e87c4350650483e85ac22e071315bf49feea.tar.bz2
perlweeklychallenge-club-34f8e87c4350650483e85ac22e071315bf49feea.zip
1st commit on 110_haskell
-rwxr-xr-xchallenge-110/stuart-little/haskell/ch-1.hs26
-rwxr-xr-xchallenge-110/stuart-little/haskell/ch-2.hs25
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