Skip to content

Commit

Permalink
Finished day13, plus added some personalized readmes
Browse files Browse the repository at this point in the history
  • Loading branch information
AgroDan committed Jan 3, 2023
1 parent 58083b6 commit e5e8738
Show file tree
Hide file tree
Showing 16 changed files with 947 additions and 1 deletion.
6 changes: 5 additions & 1 deletion day1/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Dan's Introduction

The advent of code. 25 challenges in whatever language you want. I started in Python because that's just what I know. This was a quick and dirty example.

# --- Day 1: Calorie Counting ---

Santa's reindeer typically eat regular reindeer food, but they need a lot of magical energy to deliver presents on Christmas. For that, their favorite snack is a special type of star fruit that only grows deep in the jungle. The Elves have brought you on their annual expedition to the grove where the fruit grows.
Expand Down Expand Up @@ -43,7 +47,7 @@ In case the Elves get hungry and need extra snacks, they need to know which Elf

Find the Elf carrying the most Calories. How many total Calories is that Elf carrying?

Your puzzle answer was 67016.
Your puzzle answer was `67016`.

# --- Part Two ---

Expand Down
4 changes: 4 additions & 0 deletions day10/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Dan's Introduction

This was such a cool challenge! Part 1 built the foundation, Part 2 used what you created in part 1 to actually draw letters! I loved this one so much. Once I got it to work I nearly jumped out of my chair.

# --- Day 10: Cathode-Ray Tube ---

You avoid the ropes, plunge into the river, and swim to shore.
Expand Down
6 changes: 6 additions & 0 deletions day11/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Dan's Introduction

This is starting to get fairly complex. We have to create a fairly complex object involving monkeys that interact with each other. The objects had to be aware of each monkey and had to manipulate their contents (IE, monkey A would throw an object to monkey B, so subtract this item from monkey A and push it onto the monkey B item stack).

Was complex but workable. This was a cool one.

# --- Day 11: Monkey in the Middle ---

As you finally start making your way upriver, you realize your pack is much lighter than you remember. Just then, one of the items from your pack goes flying overhead. Monkeys are playing Keep Away with your missing things!
Expand Down
4 changes: 4 additions & 0 deletions day12_2/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Dan's Introduction

Please read what I wrote in [day12](../day12/README.md). That pretty much sums up the entire challenge and all of my failures learned from it.

# --- Day 12: Hill Climbing Algorithm ---

You try contacting the Elves using your handheld device, but the river you're following must be too low to get a decent signal.
Expand Down
175 changes: 175 additions & 0 deletions day13/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Dan's Introduction

This wasn't nearly as difficult as day 12, but still very difficult. The good thing here are the two things I learned from this process: nil interfaces (and interfaces in general), as well as how to create a separate file of util functions and still run them properly using `go run`. Specifically, to run this program you run `go run day13.go sort.go`.

The first part involved ingesting the data using a JSON module to read each value properly, as well as how to handle the concept of the `[]interface{}` datatype, which for my purposes was a "datatype of anything." If you have a list of objects that are multiple data types, it's best to lump them into the `[]interface{}` type and then do some [Type Assertions](https://go.dev/tour/methods/15) to check what kind of datatype we're _actually_ using here and act accordingly.

Go sure has its quirks, but it's still pretty elegant.

The other sweet thing is that I wrote my own `MergeSort()` function to perform part 2 of this. I could have used the built-ins, but I just really wanted to write my own. Honestly getting the `MergeSort()` function to actually work is one of my favorite parts of this challenge.

# --- Day 13: Distress Signal ---

You climb the hill and again try contacting the Elves. However, you instead receive a signal you weren't expecting: a distress signal.

Your handheld device must still not be working properly; the packets from the distress signal got decoded out of order. You'll need to re-order the list of received packets (your puzzle input) to decode the message.

Your list consists of pairs of packets; pairs are separated by a blank line. You need to identify how many pairs of packets are in the right order.

For example:

```
[1,1,3,1,1]
[1,1,5,1,1]
[[1],[2,3,4]]
[[1],4]
[9]
[[8,7,6]]
[[4,4],4,4]
[[4,4],4,4,4]
[7,7,7,7]
[7,7,7]
[]
[3]
[[[]]]
[[]]
[1,[2,[3,[4,[5,6,7]]]],8,9]
[1,[2,[3,[4,[5,6,0]]]],8,9]
```

Packet data consists of lists and integers. Each list starts with [, ends with ], and contains zero or more comma-separated values (either integers or other lists). Each packet is always a list and appears on its own line.

When comparing two values, the first value is called left and the second value is called right. Then:

If both values are integers, the lower integer should come first. If the left integer is lower than the right integer, the inputs are in the right order. If the left integer is higher than the right integer, the inputs are not in the right order. Otherwise, the inputs are the same integer; continue checking the next part of the input.
If both values are lists, compare the first value of each list, then the second value, and so on. If the left list runs out of items first, the inputs are in the right order. If the right list runs out of items first, the inputs are not in the right order. If the lists are the same length and no comparison makes a decision about the order, continue checking the next part of the input.
If exactly one value is an integer, convert the integer to a list which contains that integer as its only value, then retry the comparison. For example, if comparing [0,0,0] and 2, convert the right value to [2] (a list containing 2); the result is then found by instead comparing [0,0,0] and [2].

Using these rules, you can determine which of the pairs in the example are in the right order:

```
== Pair 1 ==
- Compare [1,1,3,1,1] vs [1,1,5,1,1]
- Compare 1 vs 1
- Compare 1 vs 1
- Compare 3 vs 5
- Left side is smaller, so inputs are in the right order
== Pair 2 ==
- Compare [[1],[2,3,4]] vs [[1],4]
- Compare [1] vs [1]
- Compare 1 vs 1
- Compare [2,3,4] vs 4
- Mixed types; convert right to [4] and retry comparison
- Compare [2,3,4] vs [4]
- Compare 2 vs 4
- Left side is smaller, so inputs are in the right order
== Pair 3 ==
- Compare [9] vs [[8,7,6]]
- Compare 9 vs [8,7,6]
- Mixed types; convert left to [9] and retry comparison
- Compare [9] vs [8,7,6]
- Compare 9 vs 8
- Right side is smaller, so inputs are not in the right order
== Pair 4 ==
- Compare [[4,4],4,4] vs [[4,4],4,4,4]
- Compare [4,4] vs [4,4]
- Compare 4 vs 4
- Compare 4 vs 4
- Compare 4 vs 4
- Compare 4 vs 4
- Left side ran out of items, so inputs are in the right order
== Pair 5 ==
- Compare [7,7,7,7] vs [7,7,7]
- Compare 7 vs 7
- Compare 7 vs 7
- Compare 7 vs 7
- Right side ran out of items, so inputs are not in the right order
== Pair 6 ==
- Compare [] vs [3]
- Left side ran out of items, so inputs are in the right order
== Pair 7 ==
- Compare [[[]]] vs [[]]
- Compare [[]] vs []
- Right side ran out of items, so inputs are not in the right order
== Pair 8 ==
- Compare [1,[2,[3,[4,[5,6,7]]]],8,9] vs [1,[2,[3,[4,[5,6,0]]]],8,9]
- Compare 1 vs 1
- Compare [2,[3,[4,[5,6,7]]]] vs [2,[3,[4,[5,6,0]]]]
- Compare 2 vs 2
- Compare [3,[4,[5,6,7]]] vs [3,[4,[5,6,0]]]
- Compare 3 vs 3
- Compare [4,[5,6,7]] vs [4,[5,6,0]]
- Compare 4 vs 4
- Compare [5,6,7] vs [5,6,0]
- Compare 5 vs 5
- Compare 6 vs 6
- Compare 7 vs 0
- Right side is smaller, so inputs are not in the right order
```

What are the indices of the pairs that are already in the right order? (The first pair has index 1, the second pair has index 2, and so on.) In the above example, the pairs in the right order are 1, 2, 4, and 6; the 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 `6187`.
# --- 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:

```
[[2]]
[[6]]
```

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:

```
[]
[[]]
[[[]]]
[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]
```

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?

Your puzzle answer was `23520`.

Both parts of this puzzle are complete! They provide two gold stars: **

At this point, you should return to your Advent calendar and try another puzzle.

If you still want to see it, you can get your puzzle input.
Loading

0 comments on commit e5e8738

Please sign in to comment.