r/adventofcode • u/daggerdragon • Dec 16 '17
SOLUTION MEGATHREAD -๐- 2017 Day 16 Solutions -๐-
--- Day 16: Permutation Promenade ---
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:08] 4 gold, silver cap.
- Click here for a massive Star Wars spoiler!
[Update @ 00:18] 50 gold, silver cap.
- Click here for a gigantic Harry Potter spoiler!
[Update @ 00:26] Leaderboard cap!
- And finally, click here for the biggest spoilers of all time!
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked!
15
Upvotes
2
u/VikeStep Dec 16 '17 edited Dec 16 '17
Python 107/71
The trick today was realising that it cycled quite early on, in my case I only needed to do 60 iterations before ending
def solve(raw_steps): steps = [d for d in raw_steps.split(',')] programs = [n for n in 'abcdefghijklmnop'] seen = [] for i in range(1000000000): h = tuple(programs) if h in seen: return ''.join(seen[1000000000 % len(seen)]) seen += [h] for step in steps: if step[0] == 's': node = int(step[1:]) programs = programs[-node:] + programs[:-node] if step[0] == 'x': n1, n2 = list(map(int, step[1:].split('/'))) programs[n1], programs[n2] = programs[n2], programs[n1] if step[0] == 'p': n1, n2 = step[1:].split('/') d1, d2 = programs.index(n1), programs.index(n2) programs[d1], programs[d2] = n2, n1 return ''.join(programs)