-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path16a_aoc.py
47 lines (40 loc) · 1.02 KB
/
16a_aoc.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
programs = [chr(ord('a')+x) for x in range(16)]
def main():
try:
while True:
i = raw_input()
# for q in xrange(1000000000):
# for x in i.split(','):
# process(x)
# if (q%10000000==0):
# print q/1000000000,'%'
for x in i.split(','):
process(x)
except EOFError:
analyse_results()
def spin(x):
global programs
l = len(programs)
programs = programs[-x:] + programs
programs = programs[:l]
def partner(a,b):
i = programs.index(a)
j = programs.index(b)
exchange(i,j)
def exchange(a,b):
k = programs[a]
programs[a] = programs[b]
programs[b] = k
def process(inp):
if inp[0]=='s':
spin(int(inp[1:]))
elif inp[0]=='x':
a,b = map(int,inp[1:].split('/'))
exchange(a,b)
elif inp[0]=='p':
a,b = inp[1],inp[3]
partner(a,b)
#print "".join(programs)
def analyse_results():
print "".join(programs)
main()