Water collected between towers: Difference between revisions
m
→{{header|Haskell}}: Tidied
Alextretyak (talk | contribs) (Added 11l) |
m (→{{header|Haskell}}: Tidied) |
||
Line 1,331:
towerPools :: [Int] -> [(Int, Int)]
towerPools =
zipWith min . scanl1 max <*> scanr1 max
>>= zipWith ((<*>) (,) . (-))
main :: IO ()
Line 1,337 ⟶ 1,338:
mapM_
(putStrLn . display . towerPools)
[ [1, 5, 3, 7, 2],
]
display :: [(Int, Int)] -> String
display = (
showTowers :: [(Int, Int)] -> String
showTowers xs =
let upper = maximum (fst <$> xs)
in '\n' :
(
. fmap
( \(x, d) ->
concat $
replicate (upper - (x + d)) " "
<> replicate x "█"
xs▼
)
)
▲ xs
showLegend :: [(Int, Int)] -> String
showLegend =
((
<*> ((" -> " <>) . show . foldr ((+) . snd) 0)</lang>
{{Out}}
<pre>
|