Mercurial > repos > other > adventofcode2023
annotate day1.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 |
rev | line source |
---|---|
0
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 --- Day 1: Trebuchet?! --- |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
3 The newly-improved calibration document consists of lines of text; each line originally contained a specific calibration value that the Elves now need to recover. On each line, the calibration value can be found by combining the first digit and the last digit (in that order) to form a single two-digit number. |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 For example: |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 1abc2 |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 pqr3stu8vwx |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 a1b2c3d4e5f |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 treb7uchet |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 In this example, the calibration values of these four lines are 12, 38, 15, and 77. Adding these together produces 142. |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 Consider your entire calibration document. What is the sum of all of the calibration values? |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 --- Part Two --- |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 Your calculation isn't quite right. It looks like some of the digits are actually spelled out with letters: one, two, three, four, five, six, seven, eight, and nine also count as valid "digits". |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 Equipped with this new information, you now need to find the real first and last digit on each line. For example: |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
22 two1nine |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 eightwothree |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 abcone2threexyz |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 xtwone3four |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 4nineeightseven2 |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 zoneight234 |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 7pqrstsixteen |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
30 In this example, the calibration values are 29, 83, 13, 24, 42, 14, and 76. Adding these together produces 281. |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
31 |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
32 What is the sum of all of the calibration values? |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
33 |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
34 |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
35 |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
36 |
76cc43966538
Start https://adventofcode.com/2023/day/1 in Ruby
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
37 Undocumented: A line with "oneight" would become 18, despite the overlap, because "one" is the first number read from the start and "8" is the last number read from the end 😐 |