Solve 2017:25 "The Halting Problem"
This commit is contained in:
parent
8b6d89fec5
commit
81c4073f32
1 changed files with 46 additions and 0 deletions
46
2017-python/solutions/day_25.py
Normal file
46
2017-python/solutions/day_25.py
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
from solutions import BaseSolution
|
||||||
|
from collections import defaultdict
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
class Solution(BaseSolution):
|
||||||
|
input_file = "25.txt"
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "Day 25: The Halting Problem"
|
||||||
|
|
||||||
|
def solve(self, puzzle_input):
|
||||||
|
T = defaultdict(int)
|
||||||
|
p = 0
|
||||||
|
|
||||||
|
hd, *states = puzzle_input.split("\n\n")
|
||||||
|
S = int(re.findall(r"(\d+) steps", hd)[0])
|
||||||
|
s = re.findall(r"state (\w)\.", hd)[0]
|
||||||
|
P = {}
|
||||||
|
for state in states:
|
||||||
|
k = re.findall(r"state (\w)\:", state)[0]
|
||||||
|
v = [int(n) for n in re.findall(r"value (\d)\.", state)]
|
||||||
|
d = re.findall(r"(left|right)\.", state)
|
||||||
|
t = re.findall(r"state (\w)\.", state)
|
||||||
|
P[k] = (v[0], d[0], t[0], v[1], d[1], t[1])
|
||||||
|
|
||||||
|
for _ in range(S):
|
||||||
|
v0, d0, s0, v1, d1, s1 = P[s]
|
||||||
|
match T[p]:
|
||||||
|
case 0:
|
||||||
|
T[p] = v0
|
||||||
|
s = s0
|
||||||
|
p += 1 if d0 == "right" else -1
|
||||||
|
case 1:
|
||||||
|
T[p] = v1
|
||||||
|
s = s1
|
||||||
|
p += 1 if d1 == "right" else -1
|
||||||
|
return sum(T.values())
|
||||||
|
|
||||||
|
def solve_again(self, puzzle_input):
|
||||||
|
return "*"
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
solution = Solution()
|
||||||
|
solution.show_results()
|
||||||
Loading…
Add table
Reference in a new issue