aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-01-23 23:00:55 +0000
committerGitHub <noreply@github.com>2021-01-23 23:00:55 +0000
commit2d191f60a7e65bc1288f877de3f22d98b1eccacc (patch)
treea8a40e72f773a134aeedcdd419a365823f61425b
parent28043c158367a5bd7898e9be8bf4b4c9d32d8afc (diff)
parentad6801162cfc8f0fe44b0db966b1e4c5e0daad69 (diff)
downloadperlweeklychallenge-club-2d191f60a7e65bc1288f877de3f22d98b1eccacc.tar.gz
perlweeklychallenge-club-2d191f60a7e65bc1288f877de3f22d98b1eccacc.tar.bz2
perlweeklychallenge-club-2d191f60a7e65bc1288f877de3f22d98b1eccacc.zip
Merge pull request #3348 from stuart-little/stuart-little_018_haskell
1st commit on 018_haskell
-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')