-
Notifications
You must be signed in to change notification settings - Fork 0
/
day5.py
61 lines (49 loc) · 1.81 KB
/
day5.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
stack0 = ['V','J', 'B', 'D']
stack1 = ['F','D', 'R', 'W', 'B', 'V', 'P']
stack2 = ['Q', 'W', 'C', 'D', 'L', 'F', 'G', 'K']
stack3 = ['B', 'D', 'N', 'L', 'M', 'P', 'J', 'W']
stack4 = ['Q', 'S', 'C', 'P', 'B', 'N', 'H']
stack5 = ['G', 'N', 'S', 'B', 'D', 'R']
stack6 = ['H','S', 'F', 'Q', 'M', 'P', 'B', 'Z']
stack7 = ['F','L', 'W']
stack8 = ['R','M', 'F', 'V', 'S']
stacks = [stack0,stack1,stack2,stack3,stack4,stack5,stack6,stack7,stack8]
for stack in stacks:
stack.reverse()
f = open("ressources/day5.txt", "r")
lines = f.readlines()
for line in lines[10:]:
instructions = line.replace("\n", "").split(" ")
nbToMove = int(instructions[1])
fromWhere = int(instructions[3])-1
toWhere = int(instructions[5])-1
for i in range(nbToMove):
item = stacks[fromWhere].pop()
stacks[toWhere].append(item)
word = ""
for stack in stacks:
word+=stack[-1]
print("Your Final Stack is: {}".format(word))
stack0 = ['V','J', 'B', 'D']
stack1 = ['F','D', 'R', 'W', 'B', 'V', 'P']
stack2 = ['Q', 'W', 'C', 'D', 'L', 'F', 'G', 'K']
stack3 = ['B', 'D', 'N', 'L', 'M', 'P', 'J', 'W']
stack4 = ['Q', 'S', 'C', 'P', 'B', 'N', 'H']
stack5 = ['G', 'N', 'S', 'B', 'D', 'R']
stack6 = ['H','S', 'F', 'Q', 'M', 'P', 'B', 'Z']
stack7 = ['F','L', 'W']
stack8 = ['R','M', 'F', 'V', 'S']
stacks = [stack0,stack1,stack2,stack3,stack4,stack5,stack6,stack7,stack8]
for line in lines[10:]:
instructions = line.replace("\n", "").split(" ")
nbToMove = int(instructions[1])
fromWhere = int(instructions[3])-1
toWhere = int(instructions[5])-1
items = stacks[fromWhere][0:nbToMove]
stacks[fromWhere] = stacks[fromWhere][nbToMove:]
stacks[toWhere] = items+stacks[toWhere]
word = ""
for stack in stacks:
word+=stack[0]
print("Your Final Stack is: {}".format(word))