AdventOfCode/2017/25/solution.py

161 lines
2.9 KiB
Python
Raw Normal View History

2024-11-30 23:15:29 +01:00
#!/bin/python3
import sys,re
from pprint import pprint
sys.path.insert(0, '../../')
from fred import list2int,get_re,nprint,lprint
input_f = 'test'
part = 1
#########################################
# #
# Part 1 #
# #
#########################################
max_steps = 12302209
begin_state = 'A'
states = {
'A': {
0: {
'W': 1,
'M': 'R',
'C': 'B'
},
1: {
'W': 0,
'M': 'L',
'C': 'D'
}
},
'B': {
0: {
'W': 1,
'M': 'R',
'C': 'C'
},
1: {
'W': 0,
'M': 'R',
'C': 'F'
}
},
'C': {
0: {
'W': 1,
'M': 'L',
'C': 'C'
},
1: {
'W': 1,
'M': 'L',
'C': 'A'
}
},
'D': {
0: {
'W': 0,
'M': 'L',
'C': 'E'
},
1: {
'W': 1,
'M': 'R',
'C': 'A'
}
},
'E': {
0: {
'W': 1,
'M': 'L',
'C': 'A'
},
1: {
'W': 0,
'M': 'R',
'C': 'B'
}
},
'F': {
0: {
'W': 0,
'M': 'R',
'C': 'C'
},
1: {
'W': 0,
'M': 'R',
'C': 'E'
}
}
}
2024-12-01 12:58:38 +01:00
# print(states)
# max_steps = 6
# begin_state = 'A'
# states = {
# 'A': {
# 0: {
# 'W': 1,
# 'M': 'R',
# 'C': 'B'
# },
# 1: {
# 'W': 0,
# 'M': 'L',
# 'C': 'B'
# }
# },
# 'B': {
# 0: {
# 'W': 1,
# 'M': 'L',
# 'C': 'A'
# },
# 1: {
# 'W': 1,
# 'M': 'R',
# 'C': 'A'
# }
# }
# }
2024-11-30 23:15:29 +01:00
if part == 1:
end = False
steps = 0
line = [0,0,0,0,0,0,0,0,0]
idx = 4
state = begin_state
while not end:
if idx-1 <= 0:
line.insert(0, [0])
idx += 1
if idx+2 > len(line):
line.append(0)
line.append(0)
cur = line[idx]
line[idx] = states[state][cur]['W']
if states[state][cur]['M'] == 'L':
idx -= 1
else:
idx += 1
state = states[state][cur]['C']
steps += 1
if steps == max_steps:
end = True
print(line.count(1))
#########################################
# #
# Part 2 #
# #
#########################################
if part == 2:
exit()