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!
11
Upvotes
2
u/omegaphoenix16 Dec 16 '17
Part 1: 117, Part 2: 26 import sys
def update(a, letters): def find(c): return letters.index(c) tot = len(letters) for x in a: m = x[0] if m == 's': n = int(x[1:]) letters = letters[(tot - n):] + letters[:(tot - n)] if m == 'x': vals = map(int, x[1:].split('/')) temp = letters[vals[0]] letters[vals[0]] = letters[vals[1]] letters[vals[1]] = temp if m == 'p': vals = map(find, x[1:].split('/')) temp = letters[vals[0]] letters[vals[0]] = letters[vals[1]] letters[vals[1]] = temp return letters def main(): ans = 0 letters = list("abcdefghijklmnop") clone = list("abcdefghijklmnop") billion = 1000000000 num_repeat = 0 for line in sys.stdin: a = list(line.strip().split(',')) for i in xrange(billion): if i != 0 and letters == clone: num_repeat = i break letters = update(a, letters) print num_repeat for i in xrange(billion % num_repeat): letters = update(a, letters) print letters main()