Equilibrium index: Difference between revisions

Content added Content deleted
m (→‎{{header|Perl}}: Fix link: Perl 6 --> Raku)
Line 1,152: Line 1,152:
<lang haskell>equilibriumIndices :: [Int] -> [Int]
<lang haskell>equilibriumIndices :: [Int] -> [Int]
equilibriumIndices xs =
equilibriumIndices xs =
let matchIndex (x, y, i) a
foldr
(\(x, y, i) a ->
| x == y = (i : a)
(if x == y
| otherwise = a
in foldr
then i : a
else a))
matchIndex
[]
[]
(zip3
(zip3
(scanl1 (+) xs) -- Sums from the left
(scanl1 (+) xs) -- Sums from the left
(scanr1 (+) xs) -- Sums from the right
(scanr1 (+) xs) -- Sums from the right
[0 ..] -- Indices
[0 ..] -- Indices
)
)


-- TEST -----------------------------------------------------------------------
---------------------------TEST----------------------------
main :: IO ()
main :: IO ()
main =
main =