Equilibrium index: Difference between revisions

m
m (→‎{{header|Haskell}}: Tidied the Prelude functions version)
Line 2,101:
equals the sum of values to the right.'''
def go(xs):
'''Left scan from accumulate, right scan derived from left'''
right scan derived from left
])'''
ls = list(accumulate(xs))
n = ls[-1]
return [i for (i, (x, y)) in enumerate(zip(
lsi for (i, (x, y)) in enumerate(zip(
[n] + [n - x for x in ls[0:-1]],
)) if [n] + [n - x for x ==in yls[0:-1]]
)) if x == y
]
return go(xs) if xs else []
 
 
# TEST ------------------------- TEST -------------------------
# main :: IO ()
def main():
Line 2,129 ⟶ 2,133:
 
 
# GENERIC ------------------------- GENERIC ------------------------
 
 
# tabulated :: String -> (a -> b) -> [a] -> String
def tabulated(s):
'''heading -> function -> input List -> tabulated output string'''
-> tabulated output string
def go(f, xs):
'''
def go(f, xs):
def width(x):
return len(str(x))
wdef = width(maxcols(xs, key=width)):
return s + '\n' +w '\n'.join= width([max(xs, key=width))
str(x).rjust(w,return ' ')s + ' -> \n' + str'\n'.join(f(x)) for x in xs[
str(x).rjust(w, ' ') + ' -> ' + str(f(x))
])
return lambda f: lambda xs: go(f, for x in xs)
])
return cols
return go
 
 
9,655

edits