I'm going to use the Food letters - A, B, C - to be the number of ounces of that food that should be used.
I'm going to put the chart here (numbers in grams/ounce):
"Food"color(white)(0)"Protein"color(white)(0)"Fat"color(white)(0)"Carbs"Food0Protein0Fat0Carbs
color(white)(00)"A"color(white)(00000)"2"color(white)(00000)"3"color(white)(000)"4"00A0000020000030004
color(white)(00)"B"color(white)(00000)"3"color(white)(00000)"3"color(white)(000)"1"00B0000030000030001
color(white)(00)"C"color(white)(00000)"3"color(white)(00000)"3"color(white)(000)"2"00C0000030000030002
And we need 24g of Protein, 27g of Fat, 20g Carbs, so:
(P)rotein: 2A+3B+3C=242A+3B+3C=24
(F)at: color(white)(000)3A+3B+3C=270003A+3B+3C=27
(C)arbs: color(white)(0)4A+1B+2C=2004A+1B+2C=20
I'm first going to work on expressing the B values in terms of A and C. I'll do that by subtracting 3xxC3×C and first P and then F:
3C: color(white)(0000)12A+3B+6C=60000012A+3B+6C=60
P: color(white)(000000)2A+3B+3C=240000002A+3B+3C=24
3C-P3C−P: 10A+color(white)(00000)3C=3610A+000003C=36
3C: color(white)(0000)12A+3B+6C=60000012A+3B+6C=60
F: color(white)(000000)3A+3B+3C=270000003A+3B+3C=27
3C-F3C−F: 9A+color(white)(000000)3C=339A+0000003C=33
And I can now subtract 3C-F3C−F from 3C-P3C−P to get rid of C and solve for A:
3C-P3C−P: 10A+color(white)(00000)3C=3610A+000003C=36
3C-F3C−F: 9A+color(white)(000000)3C=339A+0000003C=33
(3C-P)-(3C-F)(3C−P)−(3C−F): A=3A=3
And now we can substitute this back in to one of our equations (I'll do both to double check our answer this far - I'll use colours to help highlight what we're doing):
color(blue)(3C-P3C−P: 10A+3C=3610A+3C=36
3C-P3C−P: 10(3)+3C=3610(3)+3C=36
3C-P3C−P: 30+3C=3630+3C=36
3C-P3C−P: 3C=63C=6
color(blue)(3C-P3C−P: color(red)(C=2C=2
color(green)(3C-F3C−F: 9A+3C=339A+3C=33
3C-F3C−F: 9(3)+3C=339(3)+3C=33
3C-F3C−F: 27+3C=3327+3C=33
3C-F3C−F: 3C=63C=6
color(green)(3C-F3C−F: color(red)(C=2C=2
Ok - C checks out as equaling 2. Now let's substitute into one of the originals (and I'll do all 3 to show it works in all the original equations):
(P)rotein: 2A+3B+3C=242A+3B+3C=24
(P)rotein: 2(3)+3B+3(2)=242(3)+3B+3(2)=24
(P)rotein: 6+3B+6=246+3B+6=24
(P)rotein: 3B=123B=12
(P)rotein: B=4B=4
(F)at: 3A+3B+3C=273A+3B+3C=27
(F)at: 3(3)+3B+3(2)=273(3)+3B+3(2)=27
(F)at: 9+3B+6=279+3B+6=27
(F)at: 3B=123B=12
(F)at: B=4B=4
(C)arbs: 4A+1B+2C=204A+1B+2C=20
(C)arbs: 4(3)+1B+2(2)=204(3)+1B+2(2)=20
(C)arbs: 12+1B+4=2012+1B+4=20
(C)arbs: B=4B=4
Everything checks out!
(A,B,C)=(3,4,2)(A,B,C)=(3,4,2) ounces of food