diff --git a/ipynb/Golomb-Puzzle.ipynb b/ipynb/Golomb-Puzzle.ipynb index f7480ea..8c6e852 100644 --- a/ipynb/Golomb-Puzzle.ipynb +++ b/ipynb/Golomb-Puzzle.ipynb @@ -13,7 +13,7 @@ "source": [ "This problem by Solomon Golomb was presented by Gary Antonik in his 14/4/14 New York Times [Numberplay column](http://wordplay.blogs.nytimes.com/2014/04/14/rectangle):\n", "\n", - ">Say you’re given the following challenge: create a set of five rectangles that have sides of length 1, 2, 3, 4, 5, 6, 7, 8, 9 and 10 units. You can combine sides in a variety of ways: for example, you could create a set of rectangles with dimensions 1 x 3, 2 x 4, 5 x 7, 6 x 8 and 9 x 10.\n", + ">Say you’re given the following challenge: create a set of five rectangles that have sides of length 1, 2, 3, 4, 5, 6, 7, 8, 9 and 10 units. You can combine sides in a variety of ways: for example, you could create a set of rectangles with dimensions 1 x 3, 2 x 4, 5 x 7, 6 x 8 and 9 x 10.\n", ">\n", ">1. How many different sets of five rectangles are possible?\n", ">\n", @@ -21,7 +21,7 @@ ">\n", ">3. What other values for the total areas of the five rectangles are possible?\n", ">\n", - ">4. Which sets of rectangles may be assembled to form a square?\n", + ">4. Which sets of rectangles may be assembled to form a square?\n", "\n", "To me, these are interesting questions because, first, I have a (slight) personal connection to Solomon Golomb (my former colleague at USC) and to Nelson Blachman (the father of my colleague Nancy Blachman), who presented the problem to Antonik, and second, I find it interesting that the problems span the range from mathematical to computational. Let's answer them." ] @@ -645,7 +645,7 @@ "\n", "In Way 1, we could pre-sort the rectangles (say, biggest first). Then we try to put the biggest rectangle in all possible positions on the grid, and for each position that fits, try putting the second biggest rectangle in all remaining positions, and so on. As a rough estimate, assume there are on average about 10 ways to place a rectangle. Then this way will look at about 105 = 100,000 combinations.\n", "\n", - "In Way 2, we consider the positions in some fixed order; say top-to-bottom, left-to right. Take the first empty position (say, the upper left corner). Try putting each of the rectangles there, and for each one that fits, try all possible rectangles in the next empty position, and so on. There are only 5! permutations of rectangles, and each rectangle can go either horizontally or vertically, so we would have to consider 5! × 25 = 3840 combinations. Since 3840 < 100,000, I'll go with Way 2. Here is a more precise description:\n", + "In Way 2, we consider the positions in some fixed order; say top-to-bottom, left-to right. Take the first empty position (say, the upper left corner). Try putting each of the rectangles there, and for each one that fits, try all possible rectangles in the next empty position, and so on. There are only 5! permutations of rectangles, and each rectangle can go either horizontaly or vertically, so we would have to consider 5! × 25 = 3840 combinations. Since 3840 < 100,000, I'll go with Way 2. Here is a more precise description:\n", "\n", "> Way 2: To `pack` a set of rectangles onto a grid, find the first empty cell on the grid. Try in turn all possible placements of any rectangle (in either orientation) at that position. For each one that fits, try to `pack` the remaining rectangles, and return the resulting grid if one of these packings succeeds. " ] @@ -669,7 +669,7 @@ " return solution\n", "\n", "def rectangle_placements(rectangles, grid, pos):\n", - " \"Yield all (rectangles2, grid2) pairs that are the result of placing any rectangle at pos on grid.\"\n", + " \"Yield all (rect, grid) pairs that result from placing a rectangle at pos on grid.\"\n", " for (w, h) in rectangles:\n", " for rect in [(w, h), (h, w)]:\n", " grid2 = place_rectangle_at(rect, grid, pos)\n", @@ -728,7 +728,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "It would be nicer to have a graphical display of colored rectangles. I will define the function `show` which displays a grid as colored rectangles, by calling upon `html_table`, which formats any grid into HTML text." + "It would be nicer to have a graphical display of colored rectangles. I will define the function `show` which displays a grid as colored rectangles, by calling upon `html_table`, which formats any grid into HTML text. (*Note:* Github is conservative in the javascript and even CSS that it allows, so if you don't see colors in the grids below, look at this file on [nbviewer](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/master/ipynb/Golomb-Puzzle.ipynb); same file, but the rendering will definitely show the colors.)" ] }, { @@ -745,7 +745,8 @@ " display(html_table(grid, colored_cell))\n", " \n", "def html_table(grid, cell_function='