annotate day3.txt @ 39:0e17e4bd97a9 default tip

Rewrite as four-dimensional route finding The grid isn't just a 2D grid. The constraints make it 4D: * X * Y * Last direction * Number of steps in that direction By tracking all four dimensions, we can find the shortest route for _all_ combinations of the constraint. Previously, we were dropping routes that were currently longer but ended up shorter because they could take subsequent steps that other routes couldn't.
author IBBoard <dev@ibboard.co.uk>
date Sun, 22 Sep 2024 11:30:53 +0100
parents 1e16a25a9553
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
1 --- Day 3: Gear Ratios ---
2
0f4991eca11a Implement day 3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2
19
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
3 A part is missing from a system. If you can add up all the part numbers in the schematic, it should be easy to work out which part is missing.
2
0f4991eca11a Implement day 3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
19
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
5 The schematic (your puzzle input) consists of a visual representation of the system. There are lots of numbers and symbols you don't really understand, but apparently any number adjacent to a symbol, even diagonally, is a "part number" and should be included in your sum. (Periods (.) do not count as a symbol.)
2
0f4991eca11a Implement day 3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6
19
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
7 Here is an example schematic:
2
0f4991eca11a Implement day 3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8
0f4991eca11a Implement day 3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 467..114..
0f4991eca11a Implement day 3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 ...*......
0f4991eca11a Implement day 3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 ..35..633.
0f4991eca11a Implement day 3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 ......#...
0f4991eca11a Implement day 3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 617*......
0f4991eca11a Implement day 3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 .....+.58.
0f4991eca11a Implement day 3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 ..592.....
0f4991eca11a Implement day 3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 ......755.
0f4991eca11a Implement day 3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 ...$.*....
0f4991eca11a Implement day 3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 .664.598..
0f4991eca11a Implement day 3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19
0f4991eca11a Implement day 3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 In this schematic, two numbers are not part numbers because they are not adjacent to a symbol: 114 (top right) and 58 (middle right). Every other number is adjacent to a symbol and so is a part number; their sum is 4361.
0f4991eca11a Implement day 3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21
19
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
22 Of course, the actual schematic is much larger. What is the sum of all of the part numbers in the schematic?
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
23
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
24 --- Part Two ---
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
25
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
26 The missing part wasn't the only issue - one of the gears in the schematic is wrong. A gear is any * symbol that is adjacent to exactly two part numbers. Its gear ratio is the result of multiplying those two numbers together.
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
27
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
28 This time, you need to find the gear ratio of every gear and add them all up to figure out which gear needs to be replaced.
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
29
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
30 Consider the same schematic again:
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
31
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
32 467..114..
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
33 ...*......
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
34 ..35..633.
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
35 ......#...
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
36 617*......
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
37 .....+.58.
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
38 ..592.....
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
39 ......755.
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
40 ...$.*....
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
41 .664.598..
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
42
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
43 In this schematic, there are two gears. The first is in the top left; it has part numbers 467 and 35, so its gear ratio is 16345. The second gear is in the lower right; its gear ratio is 451490. (The * adjacent to 617 is not a gear because it is only adjacent to one part number.) Adding up all of the gear ratios produces 467835.
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
44
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 2
diff changeset
45 What is the sum of all of the gear ratios in your schematic?