You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
938 B
Python
51 lines
938 B
Python
stacks = [
|
|
list("SCVN")[::-1],
|
|
list("ZMJHNS")[::-1],
|
|
list("MCTGJND")[::-1],
|
|
list("TDFJWRM")[::-1],
|
|
list("PFH")[::-1],
|
|
list("CTZHJ")[::-1],
|
|
list("DPRQFSLZ")[::-1],
|
|
list("CSLHDFPW")[::-1],
|
|
list("DSMPFNGZ")[::-1]
|
|
]
|
|
|
|
l = open("in.txt", "r").read().split("\n")
|
|
|
|
# part1
|
|
for instr in l:
|
|
cmds = instr.split(" ")
|
|
ol = stacks[int(cmds[3])-1]
|
|
nl = stacks[int(cmds[5])-1]
|
|
take = int(cmds[1])
|
|
for _ in range(take):
|
|
old = ol[0]
|
|
nl.insert(0, old)
|
|
del ol[0]
|
|
|
|
print(''.join([stk[0] for stk in stacks]))
|
|
|
|
stacks2 = [
|
|
list("SCVN"),
|
|
list("ZMJHNS"),
|
|
list("MCTGJND"),
|
|
list("TDFJWRM"),
|
|
list("PFH"),
|
|
list("CTZHJ"),
|
|
list("DPRQFSLZ"),
|
|
list("CSLHDFPW"),
|
|
list("DSMPFNGZ")
|
|
]
|
|
|
|
# part2
|
|
for instr in l:
|
|
cmds = instr.split(" ")
|
|
# move 3 from 9 to 6
|
|
ol = stacks2[int(cmds[3])-1]
|
|
nl = stacks2[int(cmds[5])-1]
|
|
take = int(cmds[1])
|
|
takelist = ol[(-1 * take):]
|
|
[nl.append(e) for e in takelist]
|
|
|
|
print(''.join([stk[-1] for stk in stacks2]))
|