Beispiel #1
0
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
Beispiel #2
0
    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))
Beispiel #3
0
    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])
Beispiel #4
0
def part1():
    tape = Tape(get_input(), input_values=[1])
    tape.run()
    return tape.output[-1]
Beispiel #5
0
 def simple_test(self, _in, expected):
     tape = Tape(_in, input_values=[expected])
     tape.run()
     self.assertEqual(expected, tape.output[-1])
Beispiel #6
0
def part2():
    tape = Tape(get_input(), input_values=[2])
    tape.run()
    return tape.output
Beispiel #7
0
def run_tape(_in):
    tape = Tape(_in)
    tape.run()
    return tape.output
Beispiel #8
0
 def test_day_5_examples(self):
     _in = [1002, 4, 3, 4, 33]
     tape = Tape(_in)
     tape.run()
     self.assertEqual(99, tape._read(4))