Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 20 Online
OpenStudy (anonymous):

Any good advice about control flow for the Diophantine equations problem sets? ie checking for ax+by+cz=n (this case x,y,z = 6,9,20 & n = each in range(floor,ceiling). I think I'm asking how to iterate all combinations of 3 lists. test = range(x,{y+1}) to include last number end = test[-1] a = range(0,end,6) b = range(0,end,9) c = range(0,end,20) now i need to add a[i],b[j], & c[k] incrementing i,j,k correctly plus a total count. I know how to check for n.

OpenStudy (anonymous):

im not sure if this is what youre looking for but anyway here is my code it worked for me it prints out all possible combinations of boxes for a in range((x/6)+1): for b in range((x/9)+1): for c in range((x/20)+1): if 6*a + 9*b + 20*c == x: print "("+str(a)+","+str(b)+","+str(c)+")" btw im having trouble with problem set 2 problem 2 if you have already solved it id be very glad to hear ☻ what i figured out is that given a combination of boxes you can add 1 nugget by taking a box of 20 and adding 2boxes of 6 and one of 9 (2*6+9=21). That is subtract 20 and add 21.

OpenStudy (anonymous):

which is not always possible i forgot to mention

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!