diff options
Diffstat (limited to 'report-repair/README.org')
-rw-r--r-- | report-repair/README.org | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/report-repair/README.org b/report-repair/README.org new file mode 100644 index 0000000..32faec1 --- /dev/null +++ b/report-repair/README.org @@ -0,0 +1,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. |