def test_example_1(self): _in = [ 109, 1, 204, -1, 1001, 100, 1, 100, 1008, 100, 16, 101, 1006, 101, 0, 99 ] tape = Tape(_in) tape.run() self.assertEqual(_in, run_tape(_in))
def calculate_amplitude(settings): previous_signal = 0 for setting in settings: input_values = (i for i in [setting, previous_signal]) tape = Tape(get_input(), input_values=input_values) tape.run() previous_signal = tape.output[-1] return previous_signal
def test_examples(self): self.simple_test([109, -1, 4, 1, 99], -1) self.simple_test([109, -1, 104, 1, 99], 1) self.simple_test([109, 1, 9, 2, 204, -6, 99], 204) self.simple_test([109, 1, 109, 9, 204, -6, 99], 204) self.simple_test([109, 1, 209, -1, 204, -106, 99], 204) self.simple_test([109, 1, 3, 3, 204, 2, 99], 424242) self.simple_test([109, 1, 203, 2, 204, 2, 99], 424242) test = [1102, 34915192, 34915192, 7, 4, 7, 99, 0] tape = Tape(test) tape.run() self.assertEqual(16, len(str(tape.output[-1]))) test = [104, 1125899906842624, 99] tape = Tape(test) tape.run() self.assertEqual(1125899906842624, tape.output[-1])
def calculate_amplitude_2(settings): tapes = [] for setting in settings: tapes.append(Tape(get_input(), input_values=[setting])) tapes[0].add_input(0) while all(not tape.finished for tape in tapes): for tape_index, tape in enumerate(tapes): should_continue = tape.step() while should_continue and not tape.finished: should_continue = tape.step() output = tape.output[-1] tapes[(tape_index + 1) % 5].add_input(output) return tapes[-1].output[-1]
def code_for_point(point): tape = Tape.tape_from_challenge(19, input_values=point) tape.run() return StatusCode(tape.output[-1])
def part1(): tape = Tape(get_input(), input_values=[1]) tape.run() return tape.output[-1]
def simple_test(self, _in, expected): tape = Tape(_in, input_values=[expected]) tape.run() self.assertEqual(expected, tape.output[-1])
def part2(): tape = Tape(get_input(), input_values=[2]) tape.run() return tape.output
def get_input(): with open("inputs/day13.txt") as f: values = list(map(int, f.read().strip().split(","))) return Game(Tape(values))
def part2(): explorer = Tape.tape_from_challenge(15, Explorer) explorer.explore() return max(explorer.distances_from(explorer.oxygen).values()) + 1
def part1(): explorer = Tape.tape_from_challenge(15, Explorer) explorer.explore() path_to_oxygen = explorer.find_path(Point(0, 0), explorer.oxygen) return len(path_to_oxygen)
def run_tape(_in): tape = Tape(_in) tape.run() return tape.output
def test_day_5_examples(self): _in = [1002, 4, 3, 4, 33] tape = Tape(_in) tape.run() self.assertEqual(99, tape._read(4))
def get_input(origin_color=0): with open("inputs/day11.txt") as f: vals = list(map(int, f.read().strip().split(","))) return Robot(Tape(vals), origin_color=origin_color)
def part1(): world: World = Tape.tape_from_challenge(17, World) return sum(p.x * p.y for p in world.scaffold_points())