For the third year, I'm participating in this year's 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:
- Forget the leaderboard. Each puzzle is released at midnight Eastern, so 11pm my time. AoC is for fun, but not the kind of fun that moves me to sacrifice sleep.
- Complete day 8. I've either gotten stuck by the puzzle or overwhelmed with life/work by day 7. The latter doesn't seem like a factor this year (fingers crossed), and I hope forgetting the leaderboard helps with the former. :)
- Experiment. Last year, I started using new data structures I don't use on a daily basis, and I found out how helpful sets and maps can be. On top of that, I am the world's worst when it comes to testing code, so I'm using Jest to get better about it.
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.
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 = 'pants',
array will also return
If you want to copy an array (or an object), use the spread syntax.
YEAH. I'M SO BAD ABOUT WRITING TESTS ACTUALLY MEANS THAT I NEVER DO IT. AND I KNOW I'M NOT ALONE. FIGHT ME.