2022 day 13 part 1 (C)

This commit is contained in:
2023-01-07 18:17:02 +01:00
parent 8e00fec33c
commit f54479189b
2 changed files with 408 additions and 0 deletions

View File

@@ -141,3 +141,57 @@ sum of these indices is =13=.
Determine which pairs of packets are already in the right order. /What
is the sum of the indices of those pairs?/
Your puzzle answer was =5843=.
The first half of this puzzle is complete! It provides one gold star: *
** --- Part Two ---
Now, you just need to put /all/ of the packets in the right order.
Disregard the blank lines in your list of received packets.
The distress signal protocol also requires that you include two
additional /divider packets/:
#+begin_example
[[2]]
[[6]]
#+end_example
Using the same rules as before, organize all packets - the ones in your
list of received packets as well as the two divider packets - into the
correct order.
For the example above, the result of putting the packets in the correct
order is:
#+begin_example
[]
[[]]
[[[]]]
[1,1,3,1,1]
[1,1,5,1,1]
[[1],[2,3,4]]
[1,[2,[3,[4,[5,6,0]]]],8,9]
[1,[2,[3,[4,[5,6,7]]]],8,9]
[[1],4]
[[2]]
[3]
[[4,4],4,4]
[[4,4],4,4,4]
[[6]]
[7,7,7]
[7,7,7,7]
[[8,7,6]]
[9]
#+end_example
Afterward, locate the divider packets. To find the /decoder key/ for
this distress signal, you need to determine the indices of the two
divider packets and multiply them together. (The first packet is at
index 1, the second packet is at index 2, and so on.) In this example,
the divider packets are /10th/ and /14th/, and so the decoder key is
=140=.
Organize all of the packets into the correct order. /What is the decoder
key for the distress signal?/