-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdventOfCode2017-16.py
46 lines (38 loc) · 1.14 KB
/
AdventOfCode2017-16.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
programs = list('abcdefghijklmnop')
def spin(programs, idx):
idx = int(idx)
slice_idx = len(programs) - idx
return programs[slice_idx:] + programs [:slice_idx]
def exchange(programs, i, j):
(i, j) = (int(i), int(j))
temp = programs[i]
programs[i] = programs[j]
programs[j] = temp
return programs
def partner(programs,a,b):
idx_a = programs.index(a)
idx_b = programs.index(b)
programs[idx_a] = b
programs[idx_b] = a
return programs
move_map = { 's' : spin, 'x' : exchange, 'p' : partner }
move_file = open('input-16.txt', 'r')
moves = move_file.read()
moves = moves.split(',')
moves = [(m[0], m[1:]) for m in moves]
moves = [(move_map[m[0]], m[1].split('/')) for m in moves]
#initial_states = { ''.join(programs) : 0 }
get_ready = False
# after 44 iterations of the full list of dance moves, the program state is the
# same as it would be after 1
for i in range(1000000000 % 44):
print '. ',
for move in moves:
(f, args) = move
programs = f(programs, *args)
#programs_string = ''.join(programs)
#if programs_string in initial_states :
# pass
#else :
# initial_states[''.join(programs)] = i
print ''.join(programs)