My solutions to advent of code 2020

2020 has been a weird year so far, so I have been looking forward to Desember and the coding calendar. Something needs to be "normal" this year. I update this post through Desember when I have solved the days puzzles. In the Advent of Code calendar, there are two parts each day. The part 2 unlock when the first part is submitted. There are new puzzles every day from 1th of Desember until 25th of Desember. My solutions for each day, I will collect in a Github repository.

My solutions in 2020

Puzzle Language Part 1 Part 2
Day 1: Report repair Go ⭐️ ⭐️
Day 2: Password Philosophy Go ⭐️ ⭐️
Day 3: Toboggan Trajectory Go ⭐️ ⭐️
Day 4: Passport Processing C# ⭐️ ⭐️
Day 5: Binary Boarding Go ⭐️ ⭐️
Day 6: Custom Customs Go ⭐️ ⭐️
Day 7: Handy Haversacks ? ⭐️ ⭐️
Day 8: Handheld Halting Go ⭐️ ⭐️
Day 9: Encoding Error Go ⭐️ ⭐️
Day 10: Adapter Array Go ⭐️ ⭐️
Day 11: Seating System Go ⭐️ ⭐️
Day 12: Rain Risk Go ⭐️ ⭐️
Day 13: Shuttle Search Go ⭐️ ⭐️
Day 14: Docking Data Go ⭐️ ⭐️
Day 15: Rambunctious Recitation Go ⭐️ ⭐️
Day 16: Ticket Translation Go ⭐️ ⭐️
Day 17:
Day 18: Operation Order Go ⭐️ ⭐️
Day 19: Monster Messages Go ⭐️ ⭐️
Day 20: Jurassic Jigsaw Go ⭐️ ⭐️
Day 21: Allergen Assessment Go ⭐️ ⭐️
Day 22: Crab Combat Go ⭐️ ⭐️

Comments to the solutions

Day 1: Report repair
The first puzzle was an easy one, given a list of numbers the first part was to find the product of the two numbers that had the sum of 2020. The second part was the same, but this time I had to find the product of the three numbers that had the sum of 2020. I did this straight forward just looping through and breaking out when I found the numbers.

Day 2: Password Philosophy
This puzzle was easy to understand and it was just to parse some input text from a file and do simple counting.

Day 3: Toboggan Trajectory
This puzzle was fun and when I realized that the easiest way to move forward (x-axis) was to just keep the counter and modulo with the size of the x-axis it felt good. The code itself that was needed for both part 1 and 2 was quite compact and not too much.

func calculateCollisions(roadMap [][]rune, rightMove int, downMove int) int {
	treeHits := 0
	maxY := len(roadMap)
	maxX := len(roadMap[0])
	curPosX := 0
	curPosY := 0
	for curPosY < maxY {
		curPosX += rightMove
		curPosY += downMove
		if curPosY < maxY {
			if roadMap[curPosY][curPosX%maxX] == TREE {
				treeHits++
			}
		}
	}
	return treeHits
}

Day 4: Passport Processing
Today I felt for doing the puzzle in C# and just do it quick and dirty. No fancy, just wanted to solve the puzzles. The puzzle itself was fun and easy to implement.

Day 5: Binary boarding
Today I was back to solving the puzzle using Go. Todays puzzle was pretty straight forward, I was thinking about using binary search for this one, but I went with the logic one even if that probably is pretty bad for the performance. The input data is not that big that it will matter (at least yet...). The second part today, I needed to read the description a couple of times to figure out what I should solve and how I could do that. But then it was pretty easy and straight forward.

Day 6: Custom Customs
This was an easy straightforward puzzle nothing unclear in the description itself or how it could be solved. I used Go for this task.

Day 7: Handy Haversacks
...

Day 8: Handheld Halting
I liked this task, walking through a program and determine an infinite loop. Since I normally not use programming languages where I need to think about pointers and references, I made a decision that this time that should be a priority. When I then parsed the input data, I would parse it into a slice and then that slice would just be referenced when needed.

Day 9: Encoding Error
Fun and fast puzzle today. Went really well and fast to understand what needed to be done and writing the Go code to make it happen.

Day 13: Shuttle Search
The first part of this puzzle was quite simple and went fast. No problems there at all. When I came to part 2, I first tried a brute force method by looping through all the timestamps (from the minimal one mentioned), but this was going on while I was going out for a while and did not finish at all. Then it as clear that there needed another method on this one and the clue was Chinese reminder theorem. I had never heard about that before at all, so there was quite a lot of google search to read about it and how that could be implemented. It was a fun puzzle after all.

Day 14: Docking Data
Puzzle today was to find out the sum of the values on memory addresses. This I could have and it would been fun to use the time to use bit operations, but I made a parser that was quite simple.

Day 15: Rambunctious Recitation
I was almost sure that I missed something when I read the puzzle description for this one. It looked too easy and for me it was straight forward. When I got the part 2, I just change the number from 2020 to the new number and that was it.

Teis Lindemark

Read more posts by this author.