summaryrefslogtreecommitdiff
path: root/report-repair/README.org
blob: 32faec151c3349511168ce701110bc965ddfba7f (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
See: https://adventofcode.com/2020/day/1
** Part 1
*** Purpose
Given a list of numbers (report):

#+begin_example
1721
979
366
299
675
1456
#+end_example

This program takes two entries that sum to 2020 (in the above example, it is 1721 and 299) and multiplies them together.

*** Method

To do this, the program takes the full list of numbers and subtracts them from 2020:

#+begin_example
299
1041
1654
1721
1345
564
#+end_example

It stores this as a list of cons pairs:

#+begin_example
'((299 . 1721)
 (1041 . 979)
 (1654 . 366)
 (1721 . 299)
 (1345 . 675)
 (564 . 1456))
#+end_example

Now, we find a pair that is equivalent on the basis of containing the same elements, and complete the multiplication.

** Part 2
*** Purpose
Of course, we now need to find three numbers in the list that meet the same criteria...

Say we have a list:

#+begin_example
979
366
675
#+end_example

We calculate a list of key-value pairs---each number added to every other number...

#+begin_example
'((((979 366) . 1345)
   ((979 675) . 1654)
   ((366 675) . 1041))
#+end_example

Then, we perform the same operation as we did in the first part:

#+begin_example
'((((979 366 675) . 1345)
   ((979 675 366) . 1654)
   ((366 675 979) . 1041)))
#+end_example

And we simply check if all three values in the car position are in the original set of numbers.