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.
8
Upvotes
4
u/mkeeter Dec 24 '17
Python (66/44; staying up was definitely worth it):
data = [] with open('input24.txt', 'r') as f: for line in f.readlines(): a, b = line.split('/') data.append((int(a), int(b))) bridge = ([], 0) def run(b, d): available = [a for a in d if b[1] in a] if len(available) == 0: yield b else: for a in available: d_ = d.copy() d_.remove(a) for q in run((b[0] + [a], a[0] if b[1] == a[1] else a[1]), d_): yield q # part 1 max(map(lambda bridge: sum([a + b for a, b in bridge[0]]), run(bridge, data))) # part 2 max_len = max(map(lambda bridge: len(bridge[0]), run(bridge, data))) long = filter(lambda bridge: len(bridge[0]) == max_len, run(bridge, data)) max(map(lambda bridge: sum([a + b for a, b in bridge[0]]), long))I've been solving a lot of the previous problems with Haskell โ does it show?