Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
torque(weights[:p][::-1]) == torque(weights[p+1:]) solution in Clear category for Can Balance by Olpag
from typing import Iterable
def can_balance(weights: Iterable) -> int:
torque = lambda args: sum(h * i for i,h in enumerate(args,1))
for p,_ in enumerate(weights):
if torque(weights[:p][::-1]) == torque(weights[p+1:]):
return p
return -1
Sept. 20, 2019
Comments: