r/adventofcode • u/semitrop • Dec 10 '23
Help/Question [2023 Day 10 (Part 2)] Question about a possible(?) Mathematical solution using Geometry
After i finished Part2 i just thought about calculatingthe area of the polygon using the Shoelace formular (https://en.wikipedia.org/wiki/Shoelace_formula), because the loop contains all the Endpoints. From there we could rearrange the Formular given by Picks theorem (https://en.wikipedia.org/wiki/Pick%27s_theorem) to calculate all the Interior points .
I just tried implementing it but it gave me a wrong answer. Before I waste any more time on this, is this a possible approach or have I overlooked something?
30
Upvotes
3
u/comforttiger Dec 10 '23
thats how i did it
9
u/1234abcdcba4321 Dec 10 '23
It is a valid solution.
5
u/_tfa Dec 10 '23
Yes, there is a solution in the solution mega-thread. Search for language JULIA.
Actually I didn't understand how this works, but now with Pick's Theorem (Thank you for mentioning it), things become clearer.
1
u/Personal_Ad_9469 Dec 11 '23
Thats what I did. Had to some rounding with my input data at least though lol
3
u/tyder21 Dec 10 '23
This is the solution that I implemented, which resulted in a correct answer.
3
u/SpeakinTelnet Dec 10 '23
I just used the shoelace formula and adjusted for the space occupied by the endpoints
https://codeberg.org/SpeakinTelnet/AoC2023-Python/src/commit/39e4e0c0ed3efb35e77ffe2744dc2e1cf59f7ff2/src/day_10/challenge_2.py#L50
2
u/TheZigerionScammer Dec 10 '23
I saw someone make it work. Certainly not me though.
1
u/daggerdragon Dec 10 '23
Changed flair from
SpoilerstoHelp/Question. Use the right flair, please.Also FYI: your links are borked on old.reddit, so please fix them.
1
u/Akuli2 Dec 10 '23
I did this too. I didn't know Pick's theorem, but I ended up doing exactly what it does.
My idea was that the shoelace theorem gives you an area where you follow the path along its middle line. This is of course bigger than the interior area, so I looked at how much bigger each piece on the path makes it. For example, each straight line contributes 1/2 square of extra area, because the middle of the path slices it in half.
1
u/Afkadrian Dec 10 '23
I used this method, you can see my Rust solution
1
u/[deleted] Dec 10 '23
In case it's useful, here is my Pick's/Shoelace solution in Python
It might help you find your bug! Good luck
1
u/R0binBl00d Dec 10 '23
Thanks for the hint. I finished the puzzle by drawing Polygons and comparing the pixels ;-) But never heard about this theorem. Will definitely try to recreate my solution using this. My solution felt a bit like a cheat.
4
u/[deleted] Dec 10 '23
[removed] — view removed comment