mebeim / aoc

🎄 My solutions and walkthroughs for Advent of Code and more related stuff.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Day 10 - Adapter Array Part 1: Problem with the variables initialization

opened this issue · comments

Hi,

First of all, I would like to thank you for your solutions to AoC, it's amazing to have this resource, I am checking my own solutions against your code constantly and learning a lot.

I think there might be a small issue with 2020 Day 10 Part 1, particularly this sentence:

Beware though: the first time we find a match (for distance 1 and 3) it means we actually have two numbers matching.

I'm not sure what you meant by that, but I don't think that's right.

I think you are supposed to initialize the counters at zero, and that the reason your code happens to work because in your input, by chance, the first adapter has a value of 1.
See, since you didn't add the charging outlet (joltage == 0), nor the built-in joltage adapter (joltage == max(input) +3), to your nums (You did it in part 2, but you were also supposed to do it in part 1), you are missing a count of 1 and a count of 3. (Which you hard coded in your counter variables by initializing them with 1)

I really hope I didn't make a mistake, and thank you again for this repo, I'm not exaggerating when I say that I've been using it daily for the past month. Cheers

Hi @bahuet. Indeed, it looks like a slight misunderstanding of the the problem statement. In my walkthrough I say:

We want to count how many of these numbers have a difference of (A) exactly 1 and (B) exactly 3

While the problem statement says:

What is the number of 1-jolt differences multiplied by the number of 3-jolt differences?

So yeah, you got it right, that's exactly what happened. Whoops! I'll fix the code as soon as I have time. Thank you for reporting this, and also thanks for your kind words 😄

Fixed in 201a780!