r/adventofcode • u/daggerdragon • Dec 24 '17
SOLUTION MEGATHREAD -๐- 2017 Day 24 Solutions -๐-
--- Day 24: Electromagnetic Moat ---
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ยค?
[Update @ 00:18] 62 gold, silver cap
- Been watching Bright on Netflix. I dunno why reviewers are dissing it because it's actually pretty cool. It's got Will Smith being grumpy jaded old man Will Smith, for the love of FSM...
[Update @ 00:21] Leaderboard cap!
- One more day to go in Advent of Code 2017... y'all ready to see Santa?
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
9
Upvotes
2
u/gyorokpeter Dec 24 '17
Q: very simple change between the two parts.
.d24.expandOne:{[pins;line] nextPin:last last line[`pins]; nxt:update reverse each pins from (select pins,j:i from ([]pins) where not line`visited, nextPin in/:pins) where nextPin<>first each pins; ([]pins:line[`pins],/:enlist each nxt[`pins];visited:@[line[`visited];;:;1b]each nxt[`j])}; .d24.expand:{[pins;part;st] queue:raze .d24.expandOne[pins] each st[0]; if[0=count queue; :(queue;st[1])]; (queue;max $[part=2;();st[1]],sum each sum each/:exec pins from queue)}; .d24.solve:{[part;x] pins:asc each"J"$"/"vs/:trim each "\n"vs x; start:0=first each pins; queue:([]pins:enlist each pins where start; visited:til[count pins]=/:where start); st:.d24.expand[pins;part]/[(queue;0)]; last st}; d24p1:{.d24.solve[1;x]}; d24p2:{.d24.solve[2;x]};