Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Oil Pie by eegoldstraw
import fractions
#use fractions module to easily handle fractions
def divide_pie(groups):
total=0 #total number of drones to get a piece of pie
for i in groups:
total+=abs(i)
#fraction of pie remaining: set to 1 => whole initially
pie=fractions.Fraction(1,1)
#for each group subtract the relevant fraction of pie from the whole pie
for group in groups:
taken=fractions.Fraction(abs(group),total)
if group>0:
pie-=taken
else:
pie-=taken*pie
return (pie.numerator, pie.denominator)
April 21, 2020