aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-09-01 10:42:00 +0100
committerGitHub <noreply@github.com>2021-09-01 10:42:00 +0100
commit270524446694cea30010496dde866e902dfdfa5e (patch)
tree08440966b6dc236dc4953bc181b2b482ef47ee3e
parentb98e9513bb1ad4e2c16836fc3049ef4854ecf1be (diff)
parent087d615c37e3e0f02e833355f8e008bebe015b33 (diff)
downloadperlweeklychallenge-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-xchallenge-128/stuart-little/haskell/ch-1.hs13
-rwxr-xr-xchallenge-128/stuart-little/haskell/ch-2.hs12
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