Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Table for FindInstance solutions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg114583] Re: Table for FindInstance solutions
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Thu, 9 Dec 2010 06:00:55 -0500 (EST)
  • References: <idnqt7$q8h$1@smc.vnet.net>

On Dec 8, 3:41 am, MH <matthewh... at gmail.com> 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}
>  ]
> =====

TableForm[Table[Flatten@{d, If[#=={},{"","",""},{s,n,t}/.#]&@
 FindInstance[6s + 9n + 20t == d && And@@Thread[{s,n,t} >= 0],
  {s,n,t},Integers]}, {d, 6,20}], TableHeadings -> {None,
  {"\nTOTAL", "BOXES\nOF 6", "BOXES\nOF 9", "BOXES\nOF 20"}},
  TableAlignments -> {Center}, TableSpacing -> {1,3}]

           BOXES   BOXES   BOXES
   TOTAL   OF 6    OF 9    OF 20
     6       1       0       0
     7
     8
     9       0       1       0
     10
     11
     12      2       0       0
     13
     14
     15      1       1       0
     16
     17
     18      0       2       0
     19
     20      0       0       1

To buy 3 more donuts:
If there is a 6 then change it to a 9;
Otherwise change a 9 to two 6's.

So we can buy 6, 9, 12, ... ,
20, 26, 29, ... , and 40, 46, 49, ... .

Putting the three sequences together:

 6  9 ...    42    45    48    51    54 ...
26 29 ...  41    44    47    50    53 ...
         40    __    46    49    52 ...

We can buy any number beyond 43, but not 43.


  • Prev by Date: Re: Table for FindInstance solutions
  • Next by Date: slow built in functions
  • Previous by thread: Re: Table for FindInstance solutions
  • Next by thread: Puzzled by IntegerPart