Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
FP-ish solution in Creative category for Can Balance by obone
from typing import Iterable
from itertools import count
def can_balance(weights: Iterable) -> int:
torque = lambda items: sum(a * b for a, b in zip(items, count(1)))
data = [i for i in range(1, len(weights) - 1)
if torque(weights[i - 1::-1]) == torque(weights[i + 1:])]
return max(data, default=0 if len(weights) == 1 else -1)
Aug. 15, 2019