Re: Table for FindInstance solutions
- To: mathgroup at smc.vnet.net
- Subject: [mg114594] Re: Table for FindInstance solutions
- From: Daniel Lichtblau <danl at wolfram.com>
- Date: Thu, 9 Dec 2010 06:02:53 -0500 (EST)
MH wrote: > Hello. I'm trying to display in a table solutions to the equation 6S > + 9N + 20T = D, where D is an integer allowed to go from 1 to 100. I > can use FindInstance to find solutions with no problems. What'd I'd > really like, though, is a table with four columns: one column each for > D, S, N, and T. The following code gets me close to what I want, but > every entry in the last three columns is the same. And, every entry > gives the value for S, N, and T, instead of just the appropriate S or > N or T value. For example, when D = 71, that row reads > > 71 {S -> 7, N -> 1, T -> 1} {S -> 7, N -> 1, T -> 1} {S -> 7, N -> > 1, T -> 1}. > > I can interpret the correct result (7 sixes, 1 nine, and 1 twenty), > but I'd like the column to read > > 71 7 1 1 > > How can I change that? Incidentally, this problem is from a current > issue of Delta Airlines' Sky Magazine. The problem asks about a baker > who sells donuts in boxes of 6, 9, and 20. What's the largest number > of donuts you CANNOT purchase? I have the solution; I'd just like it > to look a little bit nicer. :-) > > Thanks! > > MH > > ===== > TableForm[ > Table[ > {D, > FindInstance[ > 6 S + 9 N + 20 T == D && S >= 0 && N >= 0 && T >= 0, {S, N, T}, > Integers], > FindInstance[ > 6 S + 9 N + 20 T == D && S >= 0 && N >= 0 && T >= 0, {S, N, T}, > Integers], > FindInstance[ > 6 S + 9 N + 20 T == D && S >= 0 && N >= 0 && T >= 0, {S, N, T}, > Integers] > }, > {D, 1, 20, 1}], > TableHeadings -> {None, {"TOTAL", "BOXES OF 6", "BOXES OF 9", > "BOXES OF 20"}}, > TableAlignments -> {Center}, > TableSpacing -> {1, 3} > ] > ===== That particular example is also know as the Chicken McNugget problem (from the original sizes available for purchase of for McDonalds' Chicken McNuggets). I guess the Delta Air publisher didn't want a trademark infringement problem. http://en.wikipedia.org/wiki/Coin_problem Mathematica can compute this directly via FrobeniusNumber. To answer your question, you could form the table as: Table[Flatten[{d, ({s, n, t} /. FindInstance[ 6*s + 9 *n + 20*t == d && s >= 0 && n >= 0 && t >= 0, {s, n, t}, Integers]) /. s | n | t -> ""}], {d, 1, 20, 1}] Customary caveats: (1) Generally a bad idea to start variable names with capitals. (2) Always a bad idea if the variable is N, since that is a Mathematica built-in function. Daniel Lichtblau Wolfram Research