From 2f52af69e7114dbad2ebd12f7c6d448cff24ec7f Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Sun, 4 Dec 2022 13:11:47 +0100 Subject: [PATCH] day25 --- day25.py | 69 +++++++++++++++++++++++++++++++++++++++++++++ inputs/input25 | 62 ++++++++++++++++++++++++++++++++++++++++ inputs/input25_test | 22 +++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 day25.py create mode 100644 inputs/input25 create mode 100644 inputs/input25_test diff --git a/day25.py b/day25.py new file mode 100644 index 0000000..e62bdf2 --- /dev/null +++ b/day25.py @@ -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) diff --git a/inputs/input25 b/inputs/input25 new file mode 100644 index 0000000..84dfd33 --- /dev/null +++ b/inputs/input25 @@ -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. diff --git a/inputs/input25_test b/inputs/input25_test new file mode 100644 index 0000000..52c31b4 --- /dev/null +++ b/inputs/input25_test @@ -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. \ No newline at end of file