aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-018/stuart-little/haskell/ch-1.hs11
-rwxr-xr-xchallenge-018/stuart-little/haskell/ch-2.hs17
2 files changed, 28 insertions, 0 deletions
diff --git a/challenge-018/stuart-little/haskell/ch-1.hs b/challenge-018/stuart-little/haskell/ch-1.hs
new file mode 100755
index 0000000000..1b6e296aca
--- /dev/null
+++ b/challenge-018/stuart-little/haskell/ch-1.hs
@@ -0,0 +1,11 @@
+#!/usr/bin/env runghc
+
+-- run <script> <space-separated strings>
+
+import System.Environment (getArgs,)
+import Data.List (inits,tails,isInfixOf,)
+import Data.List.Extra (maximumOn,)
+
+main = do
+ strs <- getArgs
+ putStrLn $ maximumOn length $ filter (and.(flip map strs).(isInfixOf)) $ concat $ map tails $ inits $ head strs
diff --git a/challenge-018/stuart-little/haskell/ch-2.hs b/challenge-018/stuart-little/haskell/ch-2.hs
new file mode 100755
index 0000000000..b69b487e9e
--- /dev/null
+++ b/challenge-018/stuart-little/haskell/ch-2.hs
@@ -0,0 +1,17 @@
+#!/usr/bin/env runghc
+
+-- run <script>
+
+import qualified Data.PSQueue as Q
+import Data.Maybe (fromJust,)
+
+main = do
+ let q = Q.insert "e" 5 $ Q.insert "d" 3 $ Q.insert "c" 1 $ Q.insert "b" 2 $ Q.insert "a" 1 Q.empty
+ putStrLn $ "\nInitial queue: \n" ++ (show q)
+
+ let (item,q') = fromJust $ Q.minView q
+ putStrLn $ "\nPulling lowest-priority, earliest-inserted element:"
+ putStrLn $ "\nItem: " ++ (show item)
+ putStrLn $ "\nNew queue state: \n" ++ (show q')
+
+ putStrLn $ "\nIs the queue empty? " ++ (show $ Q.null q')