r/adventofcode • • Dec 19 '17

SOLUTION MEGATHREAD -๐ŸŽ„- 2017 Day 19 Solutions -๐ŸŽ„-

--- Day 19: A Series of Tubes ---


Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).

Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


Need a hint from the Hugely* Handyโ€  Haversackโ€ก of Helpfulยง Hints^ยค?

Spoiler


AoC ops @ T-2 minutes to launch:

[23:58] <daggerdragon> ATTENTION MEATBAGS T-2 MINUTES TO LAUNCH

[23:58] <Topaz> aaaaah

[23:58] <Cheezmeister> Looks like I'll be just able to grab my input before my flight boards. Wish me luck being offline in TOPAZ's HOUSE OF PAIN^WFUN AND LEARNING

[23:58] <Topaz> FUN AND LEARNING

[23:58] <Hade> FUN IS MANDATORY

[23:58] <Skie> I'm pretty sure that's not the mandate for today

[Update @ 00:16] 69 gold, silver cap

  • My tree is finally trimmed with just about every ornament I own and it's real purdy. hbu?

[Update @ 00:18] Leaderboard cap!

  • So, was today's mandate Helpful Hint any help at all?

This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped, thread unlocked!

11 Upvotes

186 comments sorted by

View all comments

Show parent comment

2

u/onlyforthisair Dec 19 '17 edited Dec 19 '17
   direction = next(d for d in dirs if pos+d in road and d != path[-1]-pos)

Would this line work with something like the following?

    v
    |
    |
    |
 ---+
-----

It seems like it checks the four cardinal directions starting from 'right' and continuing clockwise (+1 is right, +1j is down, -1 is left, -1j is up).

Another potential situation for error would be the following:

    v
    |
    |
    |
    E
---------

With E being the end of the entire thing.

1

u/cluk Dec 19 '17

Yes, that would cause troubles, however the lines are nicely padded with spaces on all sides.

1

u/fatpollo Dec 19 '17 edited Dec 19 '17

You are correct, it would fail in the first scenario

for the second, it would get part 1 right but would count one extra step in part 2

the solution would be to ensure that + only allows turning at most 90 degrees away, not two, and that can be rolled into the if check within the next call.

edit: I changed it to allow only LR turns. It's still vulnerable to some edge cases though. like |+-, but I think I'm gonna leave it as it is.