Here I will display my solutions (of varying degree) to the advent of code anno 2017!
Go to file
Alexander Munch-Hansen d411fd9e6f Day 16 2018-01-09 13:55:32 +01:00
13.rb 13th done 2017-12-19 14:29:17 +01:00
15_1.rb 15th day done, stole Christoffers naming scheme :< 2017-12-25 23:37:11 +01:00
15_2.rb 15th day done, stole Christoffers naming scheme :< 2017-12-25 23:37:11 +01:00
16-1.rb Day 16 2018-01-09 13:55:32 +01:00
16-2.rb Day 16 2018-01-09 13:55:32 +01:00
README.md Added fifth day 2017-12-06 02:39:23 +01:00
captcha.rb First solution 2017-12-01 21:14:05 +01:00
checksum.rb Slightly prettier 2017-12-02 13:24:48 +01:00
hexagons.rb 11th day 2017-12-19 02:43:23 +01:00
i_like_registers.rb Day 8 2017-12-09 21:29:20 +01:00
knot_tying.rb 2nd part 2017-12-18 12:33:31 +01:00
memory_alloc.rb 6th day 2017-12-06 19:02:14 +01:00
my_parsing_nightmare.rb Day 9 2017-12-10 16:54:59 +01:00
passphrase.rb Day four 2017-12-04 21:32:39 +01:00
searching_for_nil.rb Fifth day 2017-12-05 23:33:24 +01:00
spirallingdistance.rb Absolutely horrible solution 2017-12-03 14:52:42 +01:00

README.md

Advent of code

This repository is dedicated to my attempts at advent of code anno 2017.

Some of the code will be somewhat quick and dirty when I first upload it, since it might be an initial attempt, however things should become somewhat clean after I've rewritten the attempts later.

The 1st of December

For the first challenge, part one, one had to review a sequence of digits and find the sum of all the digits, which match the next digit in the list. This list is circular, thus the last digit will be able to match with the first digit, such that `1221` will have a sum of `3`.

For the second part, one now had to, instead of considering the next digit in the list, consider the digit halfway around the circular list, so `1212` would produce a sum of `6`.

The 2nd of December

For the second challenge, part one, the objective was to look through a bunch of lists, find the maximum and minimum value and then subtract these for each list. In the end, the results of the different subtractions had to be summed up and this would be the result.

For the second part, the calculation of the checksum had changed to now being calculated from finding the only pair of evenly divisible numbers from each list and then sum up the results of the divisions.

The 3rd of December

The goal was to look at a spiral which followed this pattern:

and then figure out what the manhattan distance is from the input number to the center. I noticed a pattern in the bottom left corner, `9, 25, 49, ...` and then saw that the squareroot of that number concidentally was the length of the side as well. Because of this, I could find the closests number to my input, where the squareroot of that number followed that pattern, `3,5,7`. After I knew what the side length was, I could figure out where my input number was, relative to that and from there I could find the actual distance to the center.

For the second part, the spiral had changed slightly. Now every number was the sum of all surrounding numbers, so the spiral would look like this:

I was not able to find a particular pattern in this, so I ended up building the spiral, using the fact that Ruby allows for hashes to have a default value, so I could set that to 0 and then iniate (0,0) => 1 and from there count the the numbers around it. The implementation is somewhat ugly.

The 4th of December

Given a list of words, one had to figure out if the given list is a valid passphrase. A passphrase consists of a series of words (lowercase letters) separated by spaces and there can be no duplicate words in the passphrase.

This first part was simply solved by converting each list to a set by calling uniq on it and then checking if the length is the same as for the original list. If not, there must have been some duplicates.

For the second part, if any word was a permutation of another word, this list was now not a valid passphrase. Because of this, it could be solved by looping through all words, taking the permutation and then checking if either of the permutation was already known and if so, the list was decided to be not a valid passphrase.

The 5th of December

The input is a list of the offsets for each jump to where one has to go in an array. Jumps are relative: -1 moves to the previous instruction, and 2 skips the next one. Start at the first instruction in the list. The goal is to follow the jumps until one leads outside the list. Also, each jump incremented the previous offset by one.

Because of the 'outside the list' requirement, one could simply loop on while input[i] != nil in Ruby, since Ruby doesn't throw an IndexOutOfBounds-exception. Therefore, for the first part, one simply had to loop on the beforementioned while and for each iteration, then calculate the new offset and increment a counter to check how many times it has taken, since the goal was to tell when we went out of bounds.

For the second part, the only difference was that whenever the offset jumped from was 3 or higher, the offset was instead decremented by one.