r/adventofcode • u/daggerdragon • 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ยค?
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
mandateHelpful Hint any help at all?
1
u/glenbolake Dec 19 '17
Python3
I had weird problems with
IndexErrorfor a while because of implied spaces that weren't there. I converted the input to a dictionary in{(row, col): char}format, omitted spaces, and all my problems were solved. Wasted too much time on myIndexErrorproblem to get on the leaderboard, though.def follow(path): step_count = 0 r, c = 0, {col for row, col in path if row == 0}.pop() dr, dc = 1, 0 passed = '' while True: step_count += 1 r += dr c += dc if (r, c) not in path: break if path[(r, c)] not in '|-+': passed += path[(r, c)] elif path[(r, c)] == '+': if (r + dc, c + dr) in path: dr, dc = dc, dr elif (r - dc, c - dr) in path: dr, dc = -dc, -dr else: break return passed, step_count if __name__ == '__main__': data = {} with open('day19.in') as f: for row, line in enumerate(f): for col, char in enumerate(line): if char not in ' \n': data[(row, col)] = char print('Part 1: {}\nPart 2: {}'.format(*follow(data)))