Summary for those just joining us:
Advent of Code is an annual Christmas themed coding challenge that runs from December 1st until christmas. Each day the coding problems get progressively harder. We have a leaderboard and pretty good turnout, so feel free to hop in at any time and show your stuff!
Whether you have a single line monstrosity or a beautiful phone book sized stack of OOP code, you can export it in a nice little image for sharing at https://carbon.vercel.app
What did you think about today's problem?
Our Code is 2416137-393b284c (No need to share your profile, you have the option to join anonymously if you don't want us to see your github)
Jump in the discussion.
No email address required.
my best result ever, shoutout to whoever mentioned point in polygon a couple days ago, I just
import solution
'd and it runs instantly. I didn't even figure out why the area calculation was off until after I finished, I just subtracted my calculated area from the provided example's correct answer, and saw that it was about half the perimeter's length. For p1 I didn't even figure that out, I iterated across every integer coordinate in the bounding rectangle and summed whether they were inside the polygon, then added that to the perimeter length lmfaothere's still hope, fellow brainlets
Jump in the discussion.
No email address required.
Jump in the discussion.
No email address required.
More options
Context
how
can u post code
Jump in the discussion.
No email address required.
Posting code on a mobile is painful, but here's the process:
Of course that's retarded and won't work for Part 2, so just use the proper theorum of
polygon area + half polygon perimeter +1
to convert geometry based area to touched pixelsJump in the discussion.
No email address required.
More options
Context
More options
Context
More options
Context
Jump in the discussion.
No email address required.
More options
Context
Part 1 - N*N grid plus floodfill
Part 2 -
and searching for area of irregular polygon formula which ends up being 10x simpler than the dumb way
Jump in the discussion.
No email address required.
More options
Context
I did part 1 the basic way, but I was
for part 2 and forgot
a. The need to use Pick's Thm
b. The name of Pick's Thm
Jump in the discussion.
No email address required.
I solved it without using any theorems.![:marseyking: :marseyking:](https://i.rdrama.net/e/marseyking.webp)
Jump in the discussion.
No email address required.
More options
Context
More options
Context
I didn't even know about Pick's theorem until today. Neat![:marseyneat: :marseyneat:](https://i.rdrama.net/e/marseyneat.webp)
Jump in the discussion.
No email address required.
What language is that?
Jump in the discussion.
No email address required.
More options
Context
More options
Context
Jump in the discussion.
No email address required.
More options
Context
Still waiting on yesterday's part 2 to complete and now the flood fill is taking forever. This sucker better not hit a recursion limit.
Worked but I ended up mathmaxxing:
Jump in the discussion.
No email address required.
How long will you have to wait for that brute force![:marseysmug2: :marseysmug2:](https://i.rdrama.net/e/marseysmug2.webp)
Jump in the discussion.
No email address required.
It finished like a minute later and Pick-Shoelace took care of part 2 so![:scoot: :scoot:](https://i.rdrama.net/e/scoot.webp)
Jump in the discussion.
No email address required.
how u get area
Jump in the discussion.
No email address required.
Some big brain shit (credit definitely not mine):
Shoelace Algorithm
Pick's Theorem
You get the interior area with shoelace; there are a bunch of different versions, I did
x[i] × (y[i+1] - y[i-1])
for every
i
, so if you have14
corners you do it fori
=1
to14
inclusive. Thei+1
andi-1
bits wrap around if they go out of range,x
andy
are the corner coords. Add them all up and halve the result and that's your [interior] area. Then use Pick's to get the total area:area = 1 + <shoelace area> + (perimeter ÷ 2)
where
perimeter
is the sum of your borders.(If you read the explanation it talks about the number of dots on the perimeter, we're viewing it as there being a dot in the centre of every pixel, but it works out as just adding the lengths)
Jump in the discussion.
No email address required.
Okay so I am a midwit, but why do u need Pick's Theorem if Shoelace gives you the area?
Jump in the discussion.
No email address required.
Shoelace gives you the number of unit squares in the polygon, when you need the number of integer points in or on it.
For example: a 2x4 rectangle has an area of 8, but contains 15 integer points.
Jump in the discussion.
No email address required.
More options
Context
Area != #integer points inside.
Easiest example is the unit square. It has 4 integer points inside (the corners), but an area of only 1.
Jump in the discussion.
No email address required.
More options
Context
Shoelace gives the area of a slightly different shape. Put a dot at the centre of each pixel, draw infinitely thin lines connecting them - the original border shrunk half a pixel in every direction. Pick's takes this area and factors in the missing half-pixel border area.
Specifically Pick's says
I = A - B/2 + 1
, whereI
is the number of dots inside the shoelace shape (or the total interior pixel count),A
is the shoelace area (no intuitive pixel equivalent, but can calc from pixel corner coords), andB
is the perimeter of the shoelace shape (or the pixel count of the border).Since the AoC question includes the border pixels, you add another
B
and you haveans = A + B/2 + 1
, whereA
is shoelace andB
is perimeter.Jump in the discussion.
No email address required.
More options
Context
More options
Context
More options
Context
More options
Context
More options
Context
More options
Context
More options
Context
can someone please explain to me how to get the friggen area ??
This may be like the 3rd or 2nd time I've hit a brick wall for these puzzles because idfk how to get the area.
I have it so I get a padding on all four edges bcuz I thought it would help me somehow but I can't wrap my head around how to do this with just if and for loops.
Jump in the discussion.
No email address required.
https://en.wikipedia.org/wiki/Shoelace_formula
Jump in the discussion.
No email address required.
Never heard of this, neato
Jump in the discussion.
No email address required.
More options
Context
I'll try understanding this.
I guess what I really want to know, is how can I check to see whether an arbitrary point A and B situated within the enclosure is unobstructed.
e: or alternatively, if the paint bucket tool was used on the enclosure, or if the enclosure were filled with a pixel-like liquid.
e: if I start from a known outside and given that the only consecutive
#
's are horizontal, I can verify that I am inside of the loop by shooting a beam until I get a#
immediately followed by a.
as when it's a vertical, and I'd be on the inside of the enclosure.Jump in the discussion.
No email address required.
Once you know the area, the answer easily follows from https://en.wikipedia.org/wiki/Pick%27s_theorem
Jump in the discussion.
No email address required.
More options
Context
More options
Context
More options
Context
More options
Context
Snapshots:
https://carbon.vercel.app:
ghostarchive.org
archive.org
archive.ph (click to archive)
https://adventofcode.com/2023:
ghostarchive.org
archive.org
archive.ph (click to archive)
Jump in the discussion.
No email address required.
More options
Context