day25
This commit is contained in:
parent
fd8aa6af91
commit
2f52af69e7
69
day25.py
Normal file
69
day25.py
Normal file
@ -0,0 +1,69 @@
|
||||
from tools.aoc import AOCDay
|
||||
from typing import Any
|
||||
|
||||
|
||||
class Day(AOCDay):
|
||||
inputs = [
|
||||
[
|
||||
(3, "input25_test"),
|
||||
(5593, "input25")
|
||||
],
|
||||
[
|
||||
(None, "input25")
|
||||
]
|
||||
]
|
||||
|
||||
def get_blueprint(self) -> (str, int, dict):
|
||||
i = self.getInput()
|
||||
begin_state = i[0][-2]
|
||||
step_count = int(i[1].split(" ")[-2])
|
||||
blueprint = {}
|
||||
current_state = ''
|
||||
current_value_order = {}
|
||||
for line in i[3:]:
|
||||
if not line:
|
||||
blueprint[current_state].append(current_value_order)
|
||||
elif line.startswith("In state "):
|
||||
current_state = line[-2]
|
||||
blueprint[current_state] = []
|
||||
elif line.startswith(" If the current value is"):
|
||||
if line[-2] == '1':
|
||||
blueprint[current_state].append(current_value_order)
|
||||
current_value_order = {}
|
||||
elif line.startswith(" - Write"):
|
||||
current_value_order['write'] = int(line.split(" ")[-1][:-1])
|
||||
elif line.startswith(" - Move"):
|
||||
current_value_order['move'] = -1 if line.split(" ")[-1] == 'left.' else 1
|
||||
elif line.startswith(" - Continue"):
|
||||
current_value_order['continue'] = line[-2]
|
||||
|
||||
blueprint[current_state].append(current_value_order)
|
||||
|
||||
return begin_state, step_count, blueprint
|
||||
|
||||
def part1(self) -> Any:
|
||||
current_state, step_count, blueprint = self.get_blueprint()
|
||||
tape = [0]
|
||||
index = 0
|
||||
|
||||
for _ in range(step_count):
|
||||
order = blueprint[current_state][tape[index]]
|
||||
tape[index] = order['write']
|
||||
index += order['move']
|
||||
current_state = order['continue']
|
||||
|
||||
if index < 0:
|
||||
tape.insert(0, 0)
|
||||
index = 0
|
||||
if index == len(tape):
|
||||
tape.append(0)
|
||||
|
||||
return sum(tape)
|
||||
|
||||
def part2(self) -> Any:
|
||||
return ""
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
day = Day(2017, 25)
|
||||
day.run(verbose=True)
|
||||
62
inputs/input25
Normal file
62
inputs/input25
Normal file
@ -0,0 +1,62 @@
|
||||
Begin in state A.
|
||||
Perform a diagnostic checksum after 12134527 steps.
|
||||
|
||||
In state A:
|
||||
If the current value is 0:
|
||||
- Write the value 1.
|
||||
- Move one slot to the right.
|
||||
- Continue with state B.
|
||||
If the current value is 1:
|
||||
- Write the value 0.
|
||||
- Move one slot to the left.
|
||||
- Continue with state C.
|
||||
|
||||
In state B:
|
||||
If the current value is 0:
|
||||
- Write the value 1.
|
||||
- Move one slot to the left.
|
||||
- Continue with state A.
|
||||
If the current value is 1:
|
||||
- Write the value 1.
|
||||
- Move one slot to the right.
|
||||
- Continue with state C.
|
||||
|
||||
In state C:
|
||||
If the current value is 0:
|
||||
- Write the value 1.
|
||||
- Move one slot to the right.
|
||||
- Continue with state A.
|
||||
If the current value is 1:
|
||||
- Write the value 0.
|
||||
- Move one slot to the left.
|
||||
- Continue with state D.
|
||||
|
||||
In state D:
|
||||
If the current value is 0:
|
||||
- Write the value 1.
|
||||
- Move one slot to the left.
|
||||
- Continue with state E.
|
||||
If the current value is 1:
|
||||
- Write the value 1.
|
||||
- Move one slot to the left.
|
||||
- Continue with state C.
|
||||
|
||||
In state E:
|
||||
If the current value is 0:
|
||||
- Write the value 1.
|
||||
- Move one slot to the right.
|
||||
- Continue with state F.
|
||||
If the current value is 1:
|
||||
- Write the value 1.
|
||||
- Move one slot to the right.
|
||||
- Continue with state A.
|
||||
|
||||
In state F:
|
||||
If the current value is 0:
|
||||
- Write the value 1.
|
||||
- Move one slot to the right.
|
||||
- Continue with state A.
|
||||
If the current value is 1:
|
||||
- Write the value 1.
|
||||
- Move one slot to the right.
|
||||
- Continue with state E.
|
||||
22
inputs/input25_test
Normal file
22
inputs/input25_test
Normal file
@ -0,0 +1,22 @@
|
||||
Begin in state A.
|
||||
Perform a diagnostic checksum after 6 steps.
|
||||
|
||||
In state A:
|
||||
If the current value is 0:
|
||||
- Write the value 1.
|
||||
- Move one slot to the right.
|
||||
- Continue with state B.
|
||||
If the current value is 1:
|
||||
- Write the value 0.
|
||||
- Move one slot to the left.
|
||||
- Continue with state B.
|
||||
|
||||
In state B:
|
||||
If the current value is 0:
|
||||
- Write the value 1.
|
||||
- Move one slot to the left.
|
||||
- Continue with state A.
|
||||
If the current value is 1:
|
||||
- Write the value 1.
|
||||
- Move one slot to the right.
|
||||
- Continue with state A.
|
||||
Loading…
Reference in New Issue
Block a user