Can someone help me with today's second puzzle? I'...
# advent-of-code
m
Can someone help me with today's second puzzle? I'm having some trouble with comprehending it blob smile
e
is there something in particular you don't understand?
if it helps, this is exactly the example that the website provides, just in a different format.
Copy code
00100
11110
10110
10111
10101
01111
00111
11100
10000
11001
00010
01010
for oxygen, first see that the most common bit in the first column is 1, so remove everything that doesn't have a 1 in the first column:
Copy code
11110
10110
10111
10101
11100
10000
11001
then the most common bit in the second column is 0, so remove everything that doesn't have a 0 in the second column:
Copy code
10110
10111
10101
10000
and so on, until there's only 1 remaining
❤️ 1
m
What I was wondering here: couldn’t it happen that we end up with an empty list? In other words: Are the inputs designed so that can’t happen? Probably the only sensible explanation.
Otherwise we would have to remove one element at a time to prevent emptying the list, and for that the instructions don’t really specify an order of execution.
e
if a 0 or 1 is the most common bit, then there must exist some rows with that bit, so you won't ever remove every row
m
True. But for the least common part (CO2), if all the rows have the same bit, all would be removed.
t
You can't end up with an empty list because the instructions tell you when to stop...
If you only have one number left, stop; this is the rating value for which you are searching.
e
I suppose it's up to interpretation, but at least the way I handled it: if there is only 1 kind of bit, then it is both the most common bit and the least common bit
but there's also other spec ambiguities that the inputs are constructed to avoid; for AoC, I'd generally say don't worry about it unless you hit it
1
m
Sure, I ignored that question, since my solution worked. 😊
t
Ship it!
😁 1
😎 2
m
I think that the inputs are made so that none of the bits are identical for all values, so that this issue never arises. @todd.ginsberg What would your solution do in the CO2 path if for example the first bit was identical in all rows?
t
Probably exception out. I partition into two lists and for the CO2 path that second list would be empty. Real world I'd worry about that. AoC I wouldn't because Eric Wastl goes out of his way to avoid generating inputs like that. I used to write my solutions more defensively (accounting for real world conditions that can't happen in AoC land), but now I don't.
👍 1
m
oh now it made sense thanks for your help @ephemient