This message was deleted.
# show-and-tell
s
This message was deleted.
m
Today I initially used
d3.polygonContains
for part 2, but then felt guilty šŸ˜…. So solved it again without it and it was quite satisfying
šŸ‘ 1
The main pseudo code is basically • For each (not-on-path) cell in the grid • Look to the 45° diagonal NorthWest of where you are standing • Along that diagonal, count how many path tiles are either
|-FJ
• If it's an odd number, you are inside
šŸ‘ 2
The
7
or
L
shapes would count as an even number of crossings (either 0 or 2)
There's a small caveat where you may or may not have to include the
S
tile depending on what role it plays in your input
m
I tried something like that, though counting horizontally. I couldn't figure it out, mostly because I think that counting diagonally was a key insight. So instead I walked around the loop, marking it's left and right sides. Then I flood filled the left/right sides until everything is labeled either loop, left, or right. Afterwards I figured out which of left and right was the inside:
I need to rewrite my visualizer with canvas instead of nanomorph so i can show that with the full input
m
Oooooh
That's clever
Yeah I too was banging my head against the wall with trying "directly to left" and "directly above".... But every time I inspected a few images I thought...
This is very annoying because sometimes I do have to count the corners as a crossing and sometimes I don't...... Is there any way I can be certain as to whether or not the corners should count
And that's how I came up with the 45 diagonal
m
For a while I was considering doubling/tripling the grid, so that there were definitely gaps around every node, and I could walk the edges in between when casting rays
m
I talked to my friend and he tripled the grid šŸ˜‰ .... That's exactly what he did. Triple the grid and try to walk to the outside
m
full vis
m
Wow verycool
Are those shapes you use in each cell just unicode? They look great!
m
that one is all canvas, so they are just lines
If a cell has a connection north, i draw a line from the center of the cell to the top, and so on
m
Oh I see ok
f
I used D3 and didn't feel guilty
šŸ˜‚ 1
ā¤ļø 1
I FELT AWESOME
šŸ˜† 1
šŸ’Ŗ 1
I mean, you could want to solve the AoC in assembly! suit yourself
šŸ’€ 1
m
yeah, If I had remembered d3 had a polygon contains function, I definitely would have used it
f
since all edges are on a grid, though, I reckon using a custom function can be faster
m
Not only all edges are on grid. But all edges are length 1 (i.e. straight lines are broken up piecemeal)
f
yes exactly
m
So the approach I describe above was several OOM faster.... But took me like an hour to think of, and debug haha
f
You can do O(N); I've added a post-scriptum to my notebook
ā¤ļø 1