diff options
| author | chirvasitua <stuart-little@users.noreply.github.com> | 2021-01-22 18:51:10 -0500 |
|---|---|---|
| committer | chirvasitua <stuart-little@users.noreply.github.com> | 2021-01-22 18:51:10 -0500 |
| commit | ad6801162cfc8f0fe44b0db966b1e4c5e0daad69 (patch) | |
| tree | 34aa5ecfde6cc8dc7445421abfd7f0d181caaae5 | |
| parent | 45a9178d4865a7289d6856d7756468f896a04e49 (diff) | |
| download | perlweeklychallenge-club-ad6801162cfc8f0fe44b0db966b1e4c5e0daad69.tar.gz perlweeklychallenge-club-ad6801162cfc8f0fe44b0db966b1e4c5e0daad69.tar.bz2 perlweeklychallenge-club-ad6801162cfc8f0fe44b0db966b1e4c5e0daad69.zip | |
1st commit on 018_haskell
| -rwxr-xr-x | challenge-018/stuart-little/haskell/ch-1.hs | 11 | ||||
| -rwxr-xr-x | challenge-018/stuart-little/haskell/ch-2.hs | 17 |
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') |
