Flood fill was too expensive, so I tried solving it with ray casting.
I believe it is the 2nd or 3rd time during 11 runs where it has been
requested.
wip
wip
For the First time this season, pt 2 was not an epic
HOLY SHIIIT!!! facemelter.
I stared at my code in disbelief during pt 1 for several
minutes before I increased the test point from from 40
to 1000 and got the right answer.
For part 1, BFS is used since there is no need to
visit each splitter more than once to count visited
splitters.
For part 2, the code initially removed the visited
check. This failed miserably, losing momentum aound
Y=54-56.
A recursive function with memoization solves it much
faster.
Lost 20 minutes in pt 1 not rembering that a print()
of a zip consumes it and makes it not loopable: had
I just used list(zip()) or removed the print, I would
have had the answer in a decent time frame.
Pt 2 was fun! I first experienced with ljust() and
rjust(), only to realize the input was mixed. Instead,
I threated the input as a grid.
Had a bug in my aoc lib, that lost me an hour for pt 1:
The ADJ dict has SW twice, and lacks NE.
The bug is at least 2 years old. It was introduced in 661f18dca4
and apparently has never worked. I guess it has not been used
up until now.
That being said, it was straight-forward. A new helper for
grid was used the first time, as well as an improved vdbg()
function.
For the first part, I used itertools.combinations
to find the highest pairs of batteries. And as
expected, that solution did not scale well for pt 2.
I figured out that reducing batteries until the top
most 12 (and 2) remained was the correct way to go.
the _maxj(line, C) function is the hive conclusion
from the solution mega thread. I really liked this
brilliant use of a while loop to exlude batteries.
- The first char just skip the while loop. A char
emptying the battery list also does this.
I tried to solve it without regexp at first, failed
brutally. Cut the line count by 80% using a regexp
instead.
It was also funny to get all square roots.