Equilibrium index: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) 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 |
|||
⚫ | |||
| x == y = (i : a) |
|||
| otherwise = a |
|||
⚫ | |||
then i : 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---------------------------- |
|||
main :: IO () |
main :: IO () |
||
main = |
main = |