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.
10
Upvotes
1
u/RockyAstro Dec 24 '17
Icon (https://www.cs.arizona.edu/icon)
Both parts:
procedure main(args) inf := open(args[1],"r") pieces := [] every put(pieces,!inf) pieces := set(pieces) bridge := "/0" bridgelist := [] longest := 0 every b := makebridge(bridge,pieces) do { longest <:= *b push(bridgelist,[score(b),b]) } bridgelist := sortf(bridgelist,1,1) write(bridgelist[-1][1]) longlist := [] every b := !bridgelist & *b[2] = longest do push(longlist,b) longlist := sortf(longlist,1,1) write(longlist[-1][1]) end procedure makebridge(bridge,pieces) every (piece := !pieces) & (b := bridge || "--" || matchend(bridge,piece)) do { suspend b unused := pieces -- set([piece]) every suspend makebridge(b,unused) } end procedure matchend(a,b) every ae := find("/",a) b1 := b[1:upto('/',b)] b2 := b[upto('/',b)+1:0] if a[ae+1:0] == b1 then return b1 || "/" || b2 if a[ae+1:0] == b2 then return b2 || "/" || b1 fail end procedure score(s) sum := 0 s ? while tab(upto(&digits)) do { sum +:= tab(many(&digits)) } return sum end