Equilibrium index: Difference between revisions
m
→{{header|Haskell}}: Tidied the Prelude functions version
(Updated the program to compile with Nim 1.4. Changed slightly the output. Added the output.) |
m (→{{header|Haskell}}: Tidied the Prelude functions version) |
||
Line 1,151:
<lang haskell>equilibriumIndices :: [Int] -> [Int]
equilibriumIndices xs =
(scanl1 (+) xs) --
(scanr1 (+) xs) --
>>= (\(x, y, i) -> [i | x == y])
▲ (zip3
▲ [0 ..] -- Indices
--------------------------- TEST
main :: IO ()
main =
mapM_
print
<$> [ [-7, 1, 5, 2, -4, 3, 0],
]
{{Out}}
<pre>[3,6]
|