diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-09-01 10:42:00 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-01 10:42:00 +0100 |
| commit | 270524446694cea30010496dde866e902dfdfa5e (patch) | |
| tree | 08440966b6dc236dc4953bc181b2b482ef47ee3e | |
| parent | b98e9513bb1ad4e2c16836fc3049ef4854ecf1be (diff) | |
| parent | 087d615c37e3e0f02e833355f8e008bebe015b33 (diff) | |
| download | perlweeklychallenge-club-270524446694cea30010496dde866e902dfdfa5e.tar.gz perlweeklychallenge-club-270524446694cea30010496dde866e902dfdfa5e.tar.bz2 perlweeklychallenge-club-270524446694cea30010496dde866e902dfdfa5e.zip | |
Merge pull request #4829 from stuart-little/stuart-little_128_haskell
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 |
