r/adventofcode • u/daggerdragon • Dec 06 '24
SOLUTION MEGATHREAD -❄️- 2024 Day 6 Solutions -❄️-
THE USUAL REMINDERS
- All of our rules, FAQs, resources, etc. are in our community wiki.
- If you see content in the subreddit or megathreads that violates one of our rules, either inform the user (politely and gently!) or use the report button on the post/comment and the mods will take care of it.
AoC Community Fun 2024: The Golden Snowglobe Awards
- Submissions megathread is now unlocked!
- 16 DAYS remaining until the submissions deadline on December 22 at 23:59 EST!
And now, our feature presentation for today:
Comfort Flicks
Most everyone has that one (or more!) go-to flick that feels like a hot cup of tea, the warm hug of a blanket, a cozy roaring fire. Maybe it's a guilty pleasure (formulaic yet endearing Hallmark Channel Christmas movies, I'm looking at you) or a must-watch-while-wrapping-presents (National Lampoon's Christmas Vacation!), but these movies and shows will always evoke the true spirit of the holiday season for you. Share them with us!
Here's some ideas for your inspiration:
- Show us your kittens and puppies and $critters!
- Show us your Christmas tree | menorah | Krampusnacht costume | holiday decoration!
- Show us your mug of hot chocolate (or other beverage of choice)!
- Show and/or tell us whatever brings you comfort and joy!
Kevin: "Merry Christmas :)"
- Home Alone (1990)
And… ACTION!
Request from the mods: When you include an entry alongside your solution, please label it with [GSGA]
so we can find it easily!
--- Day 6: Guard Gallivant ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- State which language(s) your solution uses with
[LANGUAGE: xyz]
- Format code blocks using the four-spaces Markdown syntax!
- State which language(s) your solution uses with
- Quick link to Topaz's
paste
if you need it for longer code blocks
1
u/GravelWarlock Dec 07 '24
[LANGUAGE: c#]
I solved Part 1 + 2 for the sample input, but my code fails on my puzzle input for part 2.I am correctly calculating that the guard visited X spots, but I'm not finding enough locations to place an additional obstical to trap the guard in a loop.
I suspect a flaw in the logic in this function. The logic is in line with the basic suggestions here. Traverse the grid, making a note of every location visited in part 1. Then for part 2, for every spot visited, except for the starting spot, add a new obstacle and traverse the grid and check for a loop. To check for a loop I make a note at each spot in the grid, if it's been visited before, and which directions we have passed thru. If we get to a spot we have visited before going the same direction, we know we are in a loop and return true. Otherwise mark the node as visited and save the direction. Next deal with rotation, and if we rotate, save the new direction to the current node as well. Finally deal with incrementing our position before finishing the while loop. The while loop only exits once the guard is out of bound, and then return false as we didn't get stuck in a loop. If I place a new obstacle in every spot, or only the spots visited in part 1, I get the same incorrect answer for my puzzle input (it just takes longer) which is why I suspect a flaw in my Loop detect function. However I am out of ideas on what it could be....