Solution to Day 16: Permutation Promenade - Part 2
#aoc_d16.py | |
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(m.group(1)) | |
c2 = int(m.group(2)) | |
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 = m.group(1) | |
c1 = inp.index(e1) | |
e2 = m.group(2) | |
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