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.

36 lines
1013 B
Python

#!/usr/bin/env python3
import re
INPUT_FILE = 'input'
pattern = '^move (\d+) from (\d+) to (\d+)$'
stacks = [
['G','T','R','W'],
['G', 'C', 'H', 'P', 'M', 'S', 'V', 'W'],
['C', 'L', 'T', 'S', 'G', 'M'],
['J', 'H', 'D', 'M', 'W', 'R', 'F'],
['P', 'Q', 'L','H','S','W','F','J'],
['P', 'J', 'D','N','F','M','S'],
['Z', 'B', 'D','F','G','C','S','J'],
['R', 'T', 'B'],
['H', 'N', 'W', 'L', 'C'],
]
def main():
content = map(str.strip, open(INPUT_FILE, 'r').readlines())
for line in content:
print(stacks)
amount, move_from, move_to = re.match(pattern, line).groups()
amount, move_from, move_to = int(amount), int(move_from)-1, int(move_to)-1
print('{}: {} -> {}'.format(amount, move_from, move_to))
temp = []
for _ in range(amount):
temp.append(stacks[move_from].pop())
temp.reverse()
stacks[move_to] += temp
for s in stacks:
print(s.pop())
if __name__ == '__main__':
main()