aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-01-23 23:00:07 +0000
committerGitHub <noreply@github.com>2021-01-23 23:00:07 +0000
commit28043c158367a5bd7898e9be8bf4b4c9d32d8afc (patch)
treec463ea2a90ffe3d67ba6b58ac83d62a115267bbe
parent107a8e61a603f38a3d7a1fd25a246bc46384f336 (diff)
parentb0f2313f16c21b6783b184384eff5741461c8d5b (diff)
downloadperlweeklychallenge-club-28043c158367a5bd7898e9be8bf4b4c9d32d8afc.tar.gz
perlweeklychallenge-club-28043c158367a5bd7898e9be8bf4b4c9d32d8afc.tar.bz2
perlweeklychallenge-club-28043c158367a5bd7898e9be8bf4b4c9d32d8afc.zip
Merge pull request #3342 from stuart-little/stuart-little_049_haskell
1st commit on 049_haskell
-rwxr-xr-xchallenge-049/stuart-little/haskell/ch-1.hs11
-rwxr-xr-xchallenge-049/stuart-little/haskell/ch-2.hs31
2 files changed, 42 insertions, 0 deletions
diff --git a/challenge-049/stuart-little/haskell/ch-1.hs b/challenge-049/stuart-little/haskell/ch-1.hs
new file mode 100755
index 0000000000..7399142255
--- /dev/null
+++ b/challenge-049/stuart-little/haskell/ch-1.hs
@@ -0,0 +1,11 @@
+#!/usr/bin/env runghc
+
+-- run <script> <number>
+
+import System.Environment (getArgs,)
+import Data.List (intersect,)
+import Data.List.Extra (notNull,)
+
+main = do
+ nr <- getArgs >>= return.(read::String->Int).head
+ print $ head $ dropWhile (notNull.(intersect ['2'..'9']).show) [nr,2*nr..]
diff --git a/challenge-049/stuart-little/haskell/ch-2.hs b/challenge-049/stuart-little/haskell/ch-2.hs
new file mode 100755
index 0000000000..23a1bb894f
--- /dev/null
+++ b/challenge-049/stuart-little/haskell/ch-2.hs
@@ -0,0 +1,31 @@
+#!/usr/bin/env runghc
+
+-- run <script>
+
+import qualified Data.Cache.LRU as C
+
+main = do
+ let l = C.insert 3 7 $ C.insert 2 5 $ C.insert 1 3 $ C.newLRU (Just 3)
+
+ putStrLn "\nInitial cache:"
+ print l
+
+ putStrLn "\nSeeking item at pos. 2:"
+ let (l',val) = C.lookup 2 l
+ putStrLn $ "Value: " ++ (show val)
+ putStrLn $ "Cache state: " ++ (show l')
+
+ putStrLn "\nSeeking item at pos. 1:"
+ let (l'',val) = C.lookup 1 l'
+ putStrLn $ "Value: " ++ (show val)
+ putStrLn $ "Cache state: " ++ (show l'')
+
+ putStrLn "\nSeeking item at pos. 4:"
+ let (l''',val) = C.lookup 4 l''
+ putStrLn $ "Value: " ++ (show val)
+ putStrLn $ "Cache state: " ++ (show l''')
+
+ putStrLn "\nInserting new item 9 at pos 4:"
+ let l4 = C.insert 4 9 l'''
+ putStrLn $ "Cache state: " ++ (show l4)
+