diff --git a/ipynb/Advent-2025.ipynb b/ipynb/Advent-2025.ipynb
index 95acb9a..1565b3a 100644
--- a/ipynb/Advent-2025.ipynb
+++ b/ipynb/Advent-2025.ipynb
@@ -1746,35 +1746,39 @@
"source": [
"### Part 1: What is the largest area of any rectangle you can make?\n",
"\n",
- "The Elves would like to find the largest rectangle that uses red tiles for two of its opposite corners. That's easy; we can try all combinations of two corners and take the corners with the maximum area. The only tricky part is remembering that we have to add one to the delta-x and delta-y numbers before multiplying them; the area of a square with coreners (0, 0) and (0, 1) is 4 tiles, not 1."
+ "The Elves would like to find the largest rectangle that uses red tiles for two of its opposite corners. That's easy; we can try all combinations of two corners and take the corners with the maximum area. The only tricky part is remembering that we have to add one to the delta-x and delta-y values before multiplying them; the area of a square with corners (0, 0) and (1, 1) is 4 tiles, not 1."
]
},
{
"cell_type": "code",
- "execution_count": 58,
+ "execution_count": 73,
"id": "75f2742e-9dbd-4005-a882-3d3931fb1b36",
"metadata": {},
"outputs": [],
"source": [
- "def tile_area(corners: Tuple[Point, Point]):\n",
+ "Corners = Tuple[Point, Point] # Type representing a rectangle by specifying two corners\n",
+ "\n",
+ "def tile_area(corners: Corners):\n",
" \"\"\"Area, in tiles, of a rectangle formed by tiles at these corner positions.\"\"\"\n",
" (x1, y1), (x2, y2) = corners\n",
- " return (abs(x1 - x2) + 1) * (abs(y1 - y2) + 1)"
+ " return (abs(x1 - x2) + 1) * (abs(y1 - y2) + 1)\n",
+ "\n",
+ "assert tile_area(((0, 0), (1, 1))) == 4"
]
},
{
"cell_type": "code",
- "execution_count": 59,
+ "execution_count": 74,
"id": "27f350c5-7866-4b7b-8d32-91512fcec5b9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
- "Puzzle 9.1: .0285 seconds, answer 4772103936 correct"
+ "Puzzle 9.1: .0272 seconds, answer 4772103936 correct"
]
},
- "execution_count": 59,
+ "execution_count": 74,
"metadata": {},
"output_type": "execute_result"
}
@@ -1791,9 +1795,9 @@
"source": [
"### Part 2: What is the largest area of any rectangle you can make using only red and green tiles?\n",
"\n",
- "Now we find that there are also green tiles. Every red tile is connected to the red tile before and after it (in the input list) by a straight line of green tiles. The list wraps, so the first red tile is also connected to the last red tile. This forms a closed figure, and the interior of the figure is all green. The outside of the figure, I'm guessing, is all white tiles. The elves want to know: What is the largest area of any rectangle you can make using only red and green tiles?\n",
+ "In Part 2 we pay attention to the green tiles on the floor. Every red tile is connected to the red tile before and after it (in the input list order) by a straight line of green tiles. The first red tile is also connected to the last red tile. This forms a closed figure, and the interior of the figure is also all green. (The outside of the figure, I'm guessing, is all white tiles.) The elves want to know: What is the largest area of any rectangle you can make using only red and green tiles?\n",
"\n",
- "This is a tough one! There are only 496 red tiles, so enumerating all pairs of them was easy. But there are roughly 100,0002 = 10,000,000,000 total tiles, so enumerating them would be too slow. To get some ideas, I really want to see what the red tiles look like:"
+ "This is a tough one! There are only 496 red tiles, so enumerating all pairs of them in Part 1 was easy. But there are roughly 100,0002 = 10,000,000,000 total tiles, so enumerating them would be too slow. To get some ideas, I really want to see what the red tiles look like:"
]
},
{
@@ -1828,17 +1832,16 @@
},
{
"cell_type": "code",
- "execution_count": 61,
+ "execution_count": 76,
"id": "4679e2de-15a0-408a-a3d9-6feb3eddd66a",
"metadata": {},
"outputs": [],
"source": [
- "Corners = Tuple[Point, Point] # Type representing the corners of a rectangle\n",
- "\n",
- "def split_tiles(red_tiles, d=60000) -> Tuple[List[Point], List[Point], Corners]:\n",
- " \"\"\"Split the tiles into top and bottom halves, and also return the two right-side corners.\"\"\"\n",
+ "def split_tiles(red_tiles) -> Tuple[List[Point], List[Point], Corners]:\n",
+ " \"\"\"Split the red tiles into top and bottom halves, and also return the two equatorial corners.\"\"\"\n",
+ " gap = (max(Ys(red_tiles)) - min(Ys(red_tiles))) // 2 # Look for a big gap between tiles\n",
" for i in range(len(red_tiles)):\n",
- " if distance(red_tiles[i], red_tiles[i + 1]) > d:\n",
+ " if distance(red_tiles[i], red_tiles[i + 1]) > gap:\n",
" return red_tiles[:i+2], red_tiles[i+2:], red_tiles[i+1:i+3],\n",
"\n",
"def split_tiles(red_tiles, d=60000) -> Tuple[List[Point], List[Point], Corners]:\n",
@@ -1857,7 +1860,7 @@
},
{
"cell_type": "code",
- "execution_count": 62,
+ "execution_count": 77,
"id": "f1c1f29f-7981-42de-bcab-d2aedb8a9613",
"metadata": {},
"outputs": [
@@ -1934,17 +1937,17 @@
},
{
"cell_type": "code",
- "execution_count": 64,
+ "execution_count": 78,
"id": "7f3350dd-0686-445c-990d-263bba4ba708",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
- "Puzzle 9.2: .0083 seconds, answer 1529675217 correct"
+ "Puzzle 9.2: .0049 seconds, answer 1529675217 correct"
]
},
- "execution_count": 64,
+ "execution_count": 78,
"metadata": {},
"output_type": "execute_result"
}
@@ -1993,7 +1996,9 @@
"id": "b4e35203-687a-434e-88f5-0afea9f31c57",
"metadata": {},
"source": [
- "Two remarks to be made here. One, this was the first puzzle of the year that was **difficult**. Two, my solution is **unsatisfying** in that it works for my input, and I strongly suspect that it would work for every other person's input, because Eric Wastl probably creating them all to be similar. But it does not work on every possible input allowed by the rules. To cover every possible input I would need to try every red tile as a possibility for the first corner, rather than trying just two possibilities. And the `any_intrusions` function would have to be more complex (see [ChatGPT's solution to 9.2](Advent-2025-AI.ipynb) for example). So my code solves my puzzle, I'm pretty sure it would solve your puzzle, but it doesn't solve all possible puzzles."
+ "Two remarks to be made here. One, this was the first puzzle of the year that was **difficult**. Two, my solution is **unsatisfying** in that it works for *my* input, and I strongly suspect that it would work for *your* input, because Eric Wastl probably creating them all to be similar. But it does not work on every possible input allowed by the rules. \n",
+ "\n",
+ "To cover every possible input I couldn't split the red tiles in half; I would need to consider all pairs of tile locations as possible corners. And the `any_intrusions` function would have to be more complex. See [ChatGPT's solution to 9.2](Advent-2025-AI.ipynb) for example; in general `any_intrusions` would have to cover an intrusion that spans the whole rectangle (and thus does not have a tile point inside the rectangle), as well as recognizing that if two points that are adjacent are inside the rectangle, that is not an intrusion of a non-red tile; that's just a two-wide strip of red."
]
},
{