Equilibrium index: Difference between revisions
m
→Python :: In terms of itertools.accumulate: Tidied.
m (→{{header|Haskell}}: Tidied the Prelude functions version) |
m (→Python :: In terms of itertools.accumulate: Tidied.) |
||
Line 2,101:
equals the sum of values to the right.'''
def go(xs):
'''Left scan from accumulate,
right scan derived from left
ls = list(accumulate(xs))
n = ls[-1]
return [
)) if x == y
]
return go(xs) if xs else []
#
# main :: IO ()
def main():
Line 2,129 ⟶ 2,133:
#
# tabulated :: String -> (a -> b) -> [a] -> String
def tabulated(s):
'''heading -> function -> input List
-> tabulated output string
def go(f, xs):▼
'''
def width(x):
return len(str(x))
str(x).rjust(w, ' ') + ' -> ' + str(f(x))
▲ ])
])
return cols
return go
|