aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-122/stuart-little/haskell/ch-1.hs11
-rwxr-xr-xchallenge-122/stuart-little/haskell/ch-2.hs17
2 files changed, 28 insertions, 0 deletions
diff --git a/challenge-122/stuart-little/haskell/ch-1.hs b/challenge-122/stuart-little/haskell/ch-1.hs
new file mode 100755
index 0000000000..05e1858281
--- /dev/null
+++ b/challenge-122/stuart-little/haskell/ch-1.hs
@@ -0,0 +1,11 @@
+#!/usr/bin/env runghc
+
+-- run <script> <space-separated numbers>
+
+import System.Environment (getArgs)
+
+runAvg :: (Fractional a, Num a, Enum a) => [a] -> [a]
+runAvg xs = zipWith (/) (scanl1 (+) xs) [1..]
+
+main :: IO ()
+main = getArgs >>= putStrLn . unwords . map show . runAvg . map (read::String->Double)
diff --git a/challenge-122/stuart-little/haskell/ch-2.hs b/challenge-122/stuart-little/haskell/ch-2.hs
new file mode 100755
index 0000000000..9bb1a4f919
--- /dev/null
+++ b/challenge-122/stuart-little/haskell/ch-2.hs
@@ -0,0 +1,17 @@
+#!/usr/bin/env runghc
+
+-- run <script> <score>
+
+import System.Environment (getArgs)
+
+nextComp :: Int -> [[[Int]]] -> [[[Int]]]
+nextComp bd xsss = reverse $ take bd $ it:(reverse xsss) where
+ it = concatMap (\(i,xss)-> map (i:) xss) $ zip [1..bd] $ reverse xsss
+
+comp :: Int -> Int -> [[Int]]
+comp n bd = last.last $ take n $ tail $ iterate (nextComp bd) [[[]]]
+
+main :: IO ()
+main = getArgs >>= putStrLn . unlines . map unwords . (map (map show)) . flip comp 3 . (read::String->Int) . head
+
+