Created
December 16, 2017 07:31
-
-
Save saucecode/399294d31aea41a5062b51674df13732 to your computer and use it in GitHub Desktop.
awful and unclean solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with open('day16challengeinput','r') as f: | |
data = f.read().split(',') | |
moves = [] | |
for move in data: | |
if move[0] == 's': | |
moves.append( (0, int(move[1:])) ) | |
elif move[0] == 'x': | |
moves.append( (1, int(move[1:].split('/')[0]), int(move[1:].split('/')[1])) ) | |
elif move[0] == 'p': | |
moves.append( (2, ord(move[1:].split('/')[0]), ord(move[1:].split('/')[1])) ) | |
programs = [ord(x) for x in 'abcdefghijklmnop'] | |
for r in range(int(1e9)): | |
if r % 1000 == 0 or r == 2: | |
print(r,''.join([chr(x) for x in programs])) | |
for move in moves: | |
if move[0] == 0: | |
amount = move[1] | |
programs[:0] = programs[-amount:] | |
del programs[-amount:] | |
elif move[0] == 1: | |
posA = move[1] | |
posB = move[2] | |
atPosA = programs[posA] | |
atPosB = programs[posB] | |
programs[posA] = atPosB | |
programs[posB] = atPosA | |
elif move[0] == 2: | |
posA = programs.index(move[1]) | |
posB = programs.index(move[2]) | |
atPosA = programs[posA] | |
atPosB = programs[posB] | |
programs[posA] = atPosB | |
programs[posB] = atPosA | |
print('done') | |
print(''.join([chr(x) for x in programs])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment