Add solution WITHOUT PARSER for day 5
This commit is contained in:
1 parent
cab8e7ad77
commit
7ddf003c8b
3 files changed
+661
No files matched your search
Executable
+36
@@ -0,0 +1,36 @@
|
||||
#!/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")
|
||||
|
||||
Reference in new issue
Block a user