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.
This was originally published on .
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.
Ha. Haha. Oh boy. Remember when I started this, and I tempted the fates by saying that life didn't look like it was going to become overwhelming? I was very, very wrong.
I solved day 3 while traveling earlier this month, and didn't take any notes. From the comments I left myself in my code, I had no problem with part one, but it seems my answers in part two were off by two digits. I decided this was an off-by-two error (???), and normally I'd go back and figure out what went wrong, but I got the correct answer because my first guess was too low, and my second guess was too high, and the difference between the guesses was 2, so, uh, I'm not going to rework it. Because I don't have to.
I start solving day 4 while I was still on the road, and had to put it away once I got home because life
got in the way took priority. I picked it back up today, and got through part two after looking at how others approached it. I knew I should've been using regex and
lastIndexOf but I just couldn't see how the logic would work best.
At some point around day 3, I realized, for the first time since starting to play this game in 2017, that you do not have to solve each day in sequential order. I assumed that if I wanted to do day 4, the site wouldn't let me unless I completed days 1-3 first. Had I bothered to even try clicking other days in the calendar, I would've seen that the days were only time-locked.
So now I am jumping around, avoiding the IntCode puzzles for as long as I can.
This is probably my favorite puzzle out of all of the AoC puzzles I've ever attempted. When I saw that we were playing with pixels, I started working with the intention of producing an actual image in the end. Turned out, ASCII art was just fine:
More than anything else, I'm really liking Jest, and I think I'm improving with not just writing tests but why I'm writing tests.
YEAH. I'M SO BAD ABOUT WRITING TESTS ACTUALLY MEANS THAT I NEVER DO IT. AND I KNOW I'M NOT ALONE. FIGHT ME.