summaryrefslogtreecommitdiff
path: root/trebuchet/README.org
blob: da1b6e5484c6c50bbf4a807de8a15bf1e93ea18f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
See: https://adventofcode.com/2023/day/1
** Part 1
*** Purpose
Given a list of lines of characters, each with a minimum of one integers:

#+begin_example
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet
#+end_example

Reduce each line to the first and last integer, then add all lines together. If a line contains a single integer, count that integer twice.

*** Method

The solution to this is obvious---filter the non-numeric characters out of the each line, index the first and last characters, and then make the summation.

** Part 2
*** Purpose
The next part now asserts that some spelt out numbers are unaccounted for. For example:

#+begin_example
two1nine
#+end_example

Should return the digit "29". We must calculate the new sum, with this rule in place.

*** Method
With this addition, it makes the most sense to perform some cleaning on each input string---substitute spelt numbers for actual numbers, then send it down the usual processing.

Lots of code was required to make this work---also noteworthy, is that this useful piece of information is not in the instructions:

#+begin_example
twone -> 21
#+end_example

because a letter is shared.