aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-01-12 12:57:50 +0000
committerGitHub <noreply@github.com>2021-01-12 12:57:50 +0000
commitb90eca11870b2e9c28d7a9781f947121ada5a9fe (patch)
tree84ec62011084dd0531e1c9ad8921122dccf6fe43
parentb417cca22b8f9da211952c010df3a462729a4f3e (diff)
parentc3d4ce93d3f0a2bc508df130fa1552257fa6f976 (diff)
downloadperlweeklychallenge-club-b90eca11870b2e9c28d7a9781f947121ada5a9fe.tar.gz
perlweeklychallenge-club-b90eca11870b2e9c28d7a9781f947121ada5a9fe.tar.bz2
perlweeklychallenge-club-b90eca11870b2e9c28d7a9781f947121ada5a9fe.zip
Merge pull request #3231 from stuart-little/stuart-little_024_haskell
1st commit on 024_haskell
-rwxr-xr-xchallenge-024/stuart-little/haskell/ch-1.hs3
-rwxr-xr-xchallenge-024/stuart-little/haskell/ch-2.hs16
2 files changed, 19 insertions, 0 deletions
diff --git a/challenge-024/stuart-little/haskell/ch-1.hs b/challenge-024/stuart-little/haskell/ch-1.hs
new file mode 100755
index 0000000000..28bf6aec12
--- /dev/null
+++ b/challenge-024/stuart-little/haskell/ch-1.hs
@@ -0,0 +1,3 @@
+#!/usr/bin/env runghc
+
+main = do return ()
diff --git a/challenge-024/stuart-little/haskell/ch-2.hs b/challenge-024/stuart-little/haskell/ch-2.hs
new file mode 100755
index 0000000000..ed85bda84b
--- /dev/null
+++ b/challenge-024/stuart-little/haskell/ch-2.hs
@@ -0,0 +1,16 @@
+#!/usr/bin/env runghc
+
+-- run <script> <space-separated list of file_paths>
+
+import System.Environment (getArgs,)
+import Control.Monad (liftM,)
+import Data.Maybe (fromJust,)
+import Data.List.Unique (sortUniq,)
+
+main = do
+ files <- getArgs
+ texts <- mapM ((liftM words).readFile) files
+ let wrds = sortUniq $ concat texts
+ let idx = zip files texts
+ let invidx = zip wrds $ map (\w -> filter (\fl -> elem w $ fromJust $ lookup fl idx) files) wrds
+ mapM_ putStrLn $ map (\(x,y) -> (show x) ++ " appears in: " ++ (unwords y)) $ invidx