You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

36 lines
1.1 KiB

#!/usr/bin/env python3
import sys, re
from copy import deepcopy
def parse(line):
groups = re.compile(r"move (?P<num>\d+) from (?P<from>\d+) to (?P<to>\d+)").search(line)
return groups
if __name__ == '__main__':
lines = open(sys.argv[1]).read()
start, moves = lines.split("\n\n")
moves = [tuple(map(int,parse(m).groups())) for m in moves.split('\n')[:-1]]
start = [['ignore'], ['Q','H','C','T','N','S','V','B'], ['G','B','D','W'], ['B','Q','S','T','R','W','F'],
['N','D','J','Z','S','W','G','L'],['F','V','D','P','M'],['J','W','F'],
list('VJBQNL'),list('NSQJCRTG'),list('MDWCQSJ')]
start2 = deepcopy(start)
for (num, fro, to) in moves:
for _ in range(0,num):
e = start[fro].pop(0)
start[to].insert(0,e)
for (num, fro, to) in moves:
start2[to] = start2[fro][:num] + start2[to]
start2[fro] = start2[fro][num:]
# challenge 1
res1 = ''.join([st[0] for st in start[1:]])
print("challenge 1:" + "\n" + res1 + "\n")
# challenge 2
res2 = ''.join([st[0] for st in start2[1:]])
print("challenge 2:" + "\n" + res2 + "\n")