Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Oil Pie by TovarischZhukov
def gcd(a, b):
while a != b:
if a > b: a = a - b
else: b = b - a
return a
def divide_pie(groups):
retval=[1,1]
count = sum(map(abs, groups))
for val in groups:
if val>0:
retval=[retval[0]*count-val*retval[1], retval[1]*count]
else:
retval=[retval[0]*count-retval[0]*abs(val), retval[1]*count]
retval = (retval[0]//gcd(retval[0], retval[1]), retval[1]//gcd(retval[0], retval[1])) if retval[0]>0 else (0,1)
return retval
Dec. 18, 2015