aboutsummaryrefslogtreecommitdiff
path: root/challenge-024
diff options
context:
space:
mode:
authorchirvasitua <stuart-little@users.noreply.github.com>2021-01-11 21:08:12 -0500
committerchirvasitua <stuart-little@users.noreply.github.com>2021-01-11 21:08:12 -0500
commitc3d4ce93d3f0a2bc508df130fa1552257fa6f976 (patch)
treea228ab1546a87c3b6d6b0416b20f8a68e751d116 /challenge-024
parent017145744161d53f08c461310b43f242f36ff69b (diff)
downloadperlweeklychallenge-club-c3d4ce93d3f0a2bc508df130fa1552257fa6f976.tar.gz
perlweeklychallenge-club-c3d4ce93d3f0a2bc508df130fa1552257fa6f976.tar.bz2
perlweeklychallenge-club-c3d4ce93d3f0a2bc508df130fa1552257fa6f976.zip
1st commit on 024_haskell
Diffstat (limited to 'challenge-024')
-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