Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Day 10 Part 2, bug? #16

Open
dmaahs2017 opened this issue Dec 11, 2023 · 6 comments
Open

Day 10 Part 2, bug? #16

dmaahs2017 opened this issue Dec 11, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@dmaahs2017
Copy link

dmaahs2017 commented Dec 11, 2023

I got stuck on part two for this problem, so I went to use your code as a reference. Updated my logic to match, which passes all the sample cases, however it does not work for my input data.

I then pulled your exact code and ran it on my input data and it does not work. I'm having trouble finding what the specific edge case is, but here is my input data https://gist.github.com/dmaahs2017/0f711278cd6a32e403c010a520f99285. The answer is not 444, answer too high.

I think this means there may be bug in your day10 part 2 solution, but you happened to get lucky with the input data not containing a particular edge case.

@attilakapostyak
Copy link

A similar algo worked for me, but looking for vec!['|', 'J', 'L']. It is dependent on how S (the start position) has its corner neighbors.
So I'm pretty sure it worked for Chris being lucky that it worked in that config for his data. The vec I have worked for my data.

So, probably this solution is far from ideal, to work on any data.

@ChristopherBiscardi
Copy link
Owner

the S position needs to be replaced by its associated pipe for the algorithm to be correct in all cases I believe. My input was definitely lucky for it to have worked this way.

@dmaahs2017
Copy link
Author

dmaahs2017 commented Dec 12, 2023

I did some research and found a different solution which uses this concept: "if you cast a ray, that is not colinear to any of the shapes borders, from any point. That point is within the enclosed shape if the number of intersections is odd"

So I just examine all the points in the south east direction from every point, and an odd number of boundary intersections means it's contained by the loop.

And I think with this solution hitting a L or 7 is ignored because a south east ray cast hits the corner of the loop which doesn't count as an intersection. At least that's my visual rationale.. don't fully understand the reasoning. So bless TDD for sanity

https://github.com/dmaahs2017/advent-of-code/blob/master/2023%2Fsrc%2Fbin%2Fday10.rs#L139-L147

@dmaahs2017 dmaahs2017 changed the title Day 10 Part 2 Day 10 Part 2, bug? Dec 12, 2023
@ChristopherBiscardi
Copy link
Owner

That is the same approach I took in the solution that exists in this repo. I know it as "point in polygon" but there are absolutely other names and contexts it is used in. The big difference is I'm not doing the ray diagonally, which is the adjustment that absolves the edges issue and IMO is the better solution compared to matching any edge direction

@ChristopherBiscardi
Copy link
Owner

I intend to change the solution here to be diagonal, so I'm using this issue to track that change.

@dmaahs2017
Copy link
Author

I intend to change the solution here to be diagonal, so I'm using this issue to track that change.

The answer for my input data is 435 if you want to use it for a test case

@ChristopherBiscardi ChristopherBiscardi added the bug Something isn't working label Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants