diff options
| -rwxr-xr-x | challenge-049/stuart-little/haskell/ch-1.hs | 11 | ||||
| -rwxr-xr-x | challenge-049/stuart-little/haskell/ch-2.hs | 31 |
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) + |
