diff options
| author | chirvasitua <stuart-little@users.noreply.github.com> | 2021-08-31 18:00:17 -0400 |
|---|---|---|
| committer | chirvasitua <stuart-little@users.noreply.github.com> | 2021-08-31 18:00:17 -0400 |
| commit | 087d615c37e3e0f02e833355f8e008bebe015b33 (patch) | |
| tree | 679502b149f1461ceb0bb6c50b098d6e5d999bf1 | |
| parent | 7579d184412cc66d8a2a4ad096e5c8dda0a477db (diff) | |
| download | perlweeklychallenge-club-087d615c37e3e0f02e833355f8e008bebe015b33.tar.gz perlweeklychallenge-club-087d615c37e3e0f02e833355f8e008bebe015b33.tar.bz2 perlweeklychallenge-club-087d615c37e3e0f02e833355f8e008bebe015b33.zip | |
1st commit on 128_haskell
| -rwxr-xr-x | challenge-128/stuart-little/haskell/ch-1.hs | 13 | ||||
| -rwxr-xr-x | challenge-128/stuart-little/haskell/ch-2.hs | 12 |
2 files changed, 25 insertions, 0 deletions
diff --git a/challenge-128/stuart-little/haskell/ch-1.hs b/challenge-128/stuart-little/haskell/ch-1.hs new file mode 100755 index 0000000000..613a9c5f31 --- /dev/null +++ b/challenge-128/stuart-little/haskell/ch-1.hs @@ -0,0 +1,13 @@ +#!/usr/bin/env runghc + +-- run <script> <space-separated binary words, with one word representing each row> + +import Data.List.Extra (maximumOn) +import Data.List.Split (splitOn) +import System.Environment (getArgs) + +maxZeros :: [String] -> (Int,Int) +maxZeros xs = maximumOn (\(a,b)-> a*b) $ map (\(i,j,s)-> ((j-i+1),(length s))) $ map (\(i,j)-> (i,j, maximumOn length $ splitOn "1" $ foldl1 (zipWith max) $ map (xs !!) [i..j]) ) [(i,j) | i <- [0..(length xs -1)], j <- [i..(length xs -1)]] + +main :: IO () +main = getArgs >>= putStrLn . (\(rows,cols)-> unlines $ replicate rows (replicate cols '0')) . maxZeros diff --git a/challenge-128/stuart-little/haskell/ch-2.hs b/challenge-128/stuart-little/haskell/ch-2.hs new file mode 100755 index 0000000000..b84f4b5122 --- /dev/null +++ b/challenge-128/stuart-little/haskell/ch-2.hs @@ -0,0 +1,12 @@ +#!/usr/bin/env runghc + +-- run <script> <starting arrivals followed by departures, all space-separated> + +import Data.List (sortOn) +import System.Environment (getArgs) + +pfrms :: [String] -> Int +pfrms xs = maximum $ map sum $ scanl (\station time -> (take (snd time) station) ++ ([mod (1 + (station !! (snd time))) 2]) ++ (drop (1 + (snd time)) station)) (replicate (div (length xs) 2) 0) $ sortOn fst $ map (\(x,y)-> (x, mod y (div (length xs) 2))) $ zip xs [0..] + +main :: IO () +main = getArgs >>= putStrLn.show.pfrms |
