diff options
| author | chirvasitua <stuart-little@users.noreply.github.com> | 2021-07-19 11:01:39 -0400 |
|---|---|---|
| committer | chirvasitua <stuart-little@users.noreply.github.com> | 2021-07-19 11:01:39 -0400 |
| commit | ae57b7ea5b2a80f5723f3f9ec3a9d64fca4fa30d (patch) | |
| tree | 6e4466ee8b5ebc3521638137ffe74ffe20aaa746 | |
| parent | 675c4ed9a3b441729b9558c051638027242ba77a (diff) | |
| download | perlweeklychallenge-club-ae57b7ea5b2a80f5723f3f9ec3a9d64fca4fa30d.tar.gz perlweeklychallenge-club-ae57b7ea5b2a80f5723f3f9ec3a9d64fca4fa30d.tar.bz2 perlweeklychallenge-club-ae57b7ea5b2a80f5723f3f9ec3a9d64fca4fa30d.zip | |
1st commit on 122_haskell
| -rwxr-xr-x | challenge-122/stuart-little/haskell/ch-1.hs | 11 | ||||
| -rwxr-xr-x | challenge-122/stuart-little/haskell/ch-2.hs | 17 |
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 + + |
