aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-005/stuart-little/haskell/ch-1.hs16
-rwxr-xr-xchallenge-005/stuart-little/haskell/ch-2.hs14
2 files changed, 30 insertions, 0 deletions
diff --git a/challenge-005/stuart-little/haskell/ch-1.hs b/challenge-005/stuart-little/haskell/ch-1.hs
new file mode 100755
index 0000000000..e203272a28
--- /dev/null
+++ b/challenge-005/stuart-little/haskell/ch-1.hs
@@ -0,0 +1,16 @@
+#!/usr/bin/env runghc
+
+-- run <script> <word> <path-to-dict-file>
+
+import System.Environment (getArgs,)
+import Data.List ((\\),)
+import Data.Char (toLower,)
+
+isAnagram :: String -> String -> Bool
+isAnagram wrd1 wrd2 = (null $ uc1 \\ uc2) && (null $ uc2 \\ uc1) where
+ (uc1:uc2:_) = (map.map) toLower (wrd1:[wrd2])
+
+main = do
+ (wrd:file:_) <- getArgs
+ text <- readFile file
+ mapM_ putStrLn $ filter (isAnagram wrd) $ words text
diff --git a/challenge-005/stuart-little/haskell/ch-2.hs b/challenge-005/stuart-little/haskell/ch-2.hs
new file mode 100755
index 0000000000..4085adbf2d
--- /dev/null
+++ b/challenge-005/stuart-little/haskell/ch-2.hs
@@ -0,0 +1,14 @@
+#!/usr/bin/env runghc
+
+-- run <script> <path-to-dict-file>
+
+import System.Environment (getArgs,)
+import Data.List ((\\),)
+import Data.Char (toLower,)
+import Data.List.Extra (maximumOn,groupSortOn,)
+import Data.MultiSet (fromList,)
+
+main = do
+ (file:_) <- getArgs
+ text <- readFile file
+ putStrLn $ unwords $ maximumOn length $ groupSortOn (fromList.(map toLower)) $ words text