← home

The most wonderful time of the year: Advent of Code

This is all about fun *cracks knuckles* and I am ready to have more fun than anyone else.

For the third year, I'm participating in this year's Advent of Code:

Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like. People use them as a speed contest, interview prep, company training, university coursework, practice problems, or to challenge each other.
Advent of Code

I'm posting my answers on GitHub, but I may try my hand at live-ish blogging about with updates on this post.

My goals this year are simple:

Day 1

Personally, day 1's puzzles weren't too difficult, but that was definitely welcome, since I needed to setup Jest and write tests for the first time ever 1.

I found Jest's API really easy to pick up, and I'm sure I'll find more "Oh, so that's what a test should do?" moments with it as I go along.

Day 2

I really enjoyed this day's puzzle. I had two head-scratchers though.

First, the wording of part 2 tripped me up pretty badly. It took me a long time to understand what it was asking me to do, and I kept looking at the numbers, thinking that there was a typo or maybe I'd received the wrong puzzle input somehow. Nope, just looking at the problem the wrong way.

Second, while trying to sort out the first head-scratcher, I thought I was in the Upside Down because some variables were changing without any clear reason. Specifically, when I thought I made a copy of an array, suddenly the original array was changing in sync with the copy.

It took me way too long to realize it was because I wasn't making deep copies: using a mere = to make a copy of an array only points that variable at the array you're attempting to copy. So, declaring const copy = array, then setting copy[1] = 'pants', array[1] will also return 'pants'.

If you want to copy an array (or an object), use the spread syntax.

Footnotes

  1. YEAH. I'M SO BAD ABOUT WRITING TESTS ACTUALLY MEANS THAT I NEVER DO IT. AND I KNOW I'M NOT ALONE. FIGHT ME.