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_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 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 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 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))