Professional Documents
Culture Documents
Imagine a jar containing beads numbered from 1 to N, and an unlimited supply of magic boxes, each with b compartments or cells,
where b ³ 2. All boxes have the same number of cells.
You may put in each cell nothing, or one bead, or another magic box, nested. The boxes are magical because they resize when you
nest them.
Your task, for any N and any b, is to put all the beads in one box using the smallest possible total number of boxes .
Box-Drawing Primitive
Draw a box with either vertical or horizontal orientation containing the elements in list xs and using the value of y, defaulting to the
empty string, to denote empty or "wasted" cells.
A Friend's Idea
A good friend (LGM) suggested the following idea: expand the number in base b, that is, as a polynomial in powers of b. If the
number of terms, k, is less than b, then just distribute them in the top box. Otherwise, accumulate the the b - 1 highest-power terms
in the top b - 1 cells (each will be a perfectly filled box), and distribute the rest in the last cell.
PrefixesAl_ListE :=
If@Length@lD £ 1, 80<, Prepend@RunSumDrop@l, -1D, 0DD;
In[17]:=
Manipulate@boxLGM@Floorn, 0, bD,
8b, 2, 10, 1<, 8e, 3, 10, 1<, 8n, 1, be , 1<D
In[37]:=
102
Out[37]=
1 2 3 10 11 12 19 20 21
4 5 6 13 14 15 22 23 24
7 8 9 16 17 18 25 26 27
28 29 30 37 38 39 46 47 48 82 83 84 91 92 93
34 35 36 43 44 45 52 53 54 88 89 90 97 98 99
55 56 57 64 65 66 73 74 75
58 59 60 67 68 69 76 77 78
61 62 63 70 71 72 79 80 81