diff options
| -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 |
