aboutsummaryrefslogtreecommitdiff
path: root/challenge-024
diff options
context:
space:
mode:
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