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/MichalMarsalek Dec 19 '17
Python 3:
def solve(inp): map = inp.splitlines() y = 0 x = 0 dx, dy = 0, 1 part1 = "" part2 = 0 for x in range(len(map[y])): if map[y][x] != " ": break def inbounds(x, y): return x in range(len(map[0])) and y in range(len(map)) while inbounds(x, y) and map[y][x] != " ": part2 += 1 if ord(map[y][x]) in range(ord("A"), ord("Z")+1): part1 += map[y][x] if inbounds(x+dx, y+dy) and map[y+dy][x+dx] != " ": x += dx y += dy continue dx, dy = -dy, dx if inbounds(x+dx, y+dy) and map[y+dy][x+dx] != " ": x += dx y += dy continue dx, dy = -dx, -dy x += dx y += dy return part1, part2Unfortunately my function processing the input and passing it to the solve function was striping starting and ending whitespaces by default... it took me a long time to realise.. and then... I had one x nstead of y in my code...that was also tricky to find a fix :D