September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,27 @@
equilibriumIndices :: [Int] -> [Int]
equilibriumIndices xs =
foldr
(\(x, y, i) a ->
(if x == y
then i : a
else a))
[]
(zip3
(scanl1 (+) xs) -- Sums from the left
(scanr1 (+) xs) -- Sums from the right
[0 ..] -- Indices
)
-- TEST -----------------------------------------------------------------------
main :: IO ()
main =
mapM_
print
(equilibriumIndices <$>
[ [-7, 1, 5, 2, -4, 3, 0]
, [2, 4, 6]
, [2, 9, 2]
, [1, -1, 1, -1, 1, -1, 1]
, [1]
, []
])