diff options
| -rw-r--r-- | challenge-071/stuart-little/README | 2 | ||||
| -rwxr-xr-x | challenge-071/stuart-little/haskell/ch-1.hs | 17 | ||||
| -rwxr-xr-x | challenge-071/stuart-little/haskell/ch-2.hs | 11 |
3 files changed, 29 insertions, 1 deletions
diff --git a/challenge-071/stuart-little/README b/challenge-071/stuart-little/README index 76119cbbb8..78439907de 100644 --- a/challenge-071/stuart-little/README +++ b/challenge-071/stuart-little/README @@ -1 +1 @@ -Solutions by Stuart Little. +Solutions by Stuart Little diff --git a/challenge-071/stuart-little/haskell/ch-1.hs b/challenge-071/stuart-little/haskell/ch-1.hs new file mode 100755 index 0000000000..de6d755b03 --- /dev/null +++ b/challenge-071/stuart-little/haskell/ch-1.hs @@ -0,0 +1,17 @@ +#!/usr/bin/env runghc + +-- run <script> <integer> + +import System.Environment (getArgs,) +import System.Random (newStdGen,) +import System.Random.Shuffle (shuffle',) + +peaks :: Ord a => [a] -> [a] +peaks l = map fst $ filter (\(x,xs)-> all (x>) xs) $ zip l $ map (\(l,r)-> concat [take 1 (reverse l), take 1 (tail r)]) $ map (\x-> splitAt x l) [0..length l-1] + +main = do + nr <- getArgs >>= return.(read::String->Int).head + gen <- newStdGen + let l = take nr $ shuffle' [1..50] 50 gen + putStrLn $ "Initial list: " ++ (unwords $ map show l) + putStrLn $ "Peaks: " ++ (unwords $ map show $ peaks l) diff --git a/challenge-071/stuart-little/haskell/ch-2.hs b/challenge-071/stuart-little/haskell/ch-2.hs new file mode 100755 index 0000000000..266dc65a9b --- /dev/null +++ b/challenge-071/stuart-little/haskell/ch-2.hs @@ -0,0 +1,11 @@ +#!/usr/bin/env runghc + +-- run <script> <integer> <space-separated list entries> + +import System.Environment (getArgs,) +import Data.List.Utils (join,) + +main = do + (nrstr:lst) <- getArgs + let nr = read nrstr::Int + putStrLn $ join " -> " $ (\(p,q)-> p ++ (tail q)) $ splitAt (length lst - nr) lst |
