Raymond Camden

Developer Advocate for IBM

So yep - I definitely didn't finish Advent of Code before Christmas, but I'm mostly done (20 out of 25 days) and I plan to keep at it in the next week or so. This post will cover a bunch of days, so forgive the length!

Day 15

Day 15 had an interesting concept. Given a set of discs with holes in them that turn every second, at what point would you be able to drop a ball so that as it fell, it would always hit holes. The ball falls through one disc at a time, so you have to simulate the discs turning and the ball trying to fall over time. The solution involves finding out what time to drop the ball so it falls perfectly.

The second part of the day simply added another disc - so my solution simply took the above solution and added the additional logic. So yep - I cheated - but it was still cool.

Day 16

Day 16 was an easy one. Given an input string, you simply transform it in such a way that it grows to a certain point. When it hits that point, you generater a checksum that shrinks the string again. The second part simply changes the desired length. Here is my solution.

Day 17

Day 17 involves moving through a room where the possible allowed directions based on a hash of a path you've taken through the room. Yeah, weird. The first part involves just finding the shortest path.

Day 18

Day 18 was another simple one. The concept is that you are in a room full of tiles and traps and you have to figure out how many safe tiles there are. You generate the room data by simply taking an initial string of room data and generating one line at a time, where each line is based on the last line. Simple! Part 2 just increases the number of lines.

Day 19

Day 19 involved simulating a game where elves sit in a circle and each elf takes the gifts of the person to their left. When you lose your gifts, you're taken out of the circle. The idea is to figure out which elf will get all the gifts. Part one was easy enough:

Part two added the twist that instead of taking the gift from the elf next to you, you take the one "across" from you. Figuring out which elf to take from was incredibly difficult for me. My logic was:

the elf across from me is:
floor(len/2)+1 offset

When len is the number of elves. My solution tooked about 40 minutes to run and ended up giving the wrong answer. (I checked it into the repo anyway.) This solution from Reddit ran near instantly:

Day 20

Day 20 seemed simple at first. Imagine you have a set of restricted numbers:

0-2
5-9
4-8

Given that set, what is the first allowed number? You can see it is three. Your input is a huge set of ranges like this. My solution was to sort by the lower end of the range and then loop over the ranges creating a smaller set of ranges. For example, imagine:

0-50
30-90

You can rewrite that as 0-90. Now imagine:

0-50
51-60

That can be merged into 0-60. While this seems simple, this took me forever to get working right.