Skip to content

Instantly share code, notes, and snippets.

Created December 16, 2017 13:45
What would you like to do?
Solution to Day 16: Permutation Promenade - Part 2
import re
inp = 'abcde'
inp = ''.join([chr(c+ord('a')) for c in range(0,16)])
moves = open('input_d16.txt','r').read().split(',')
def rotate(l, n):
return l[-n:] + l[:-n]
def dance(inp, moves):
for i in moves:
if i.startswith("s"):
much = int(i.replace('s',''))
inp = rotate(inp, much)
if i.startswith("x"):
m = re.match("x(\d+)/(\d+)",i)
c1 = int(
c2 = int(
d = [c for c in inp]
#print i,c1
t = d[c1]
d[c1] = d[c2]
d[c2] = t
inp = ''.join(d)
if i.startswith("p"):
m = re.match("p([a-p]+)/([a-p]+)",i)
e1 =
c1 = inp.index(e1)
e2 =
c2 = inp.index(e2)
d = [c for c in inp]
t = d[c1]
d[c1] = d[c2]
d[c2] = t
inp = ''.join(d)
return inp
for k in range(1000000000):
inp = dance(inp, moves)
print inp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment