def test_simple(self): p = Program("3, 1") p.send_input(42) p.step() self.assertEqual(p._Program__pos, 2) self.assertEqual(p._Program__running, True) self.assertEqual(p._Program__memory, [3, 42])
def test_day5_part2(self): datas = [ ( "3,21,1008,21,8,20,1005,20,22,107,8,21,20,1006,20,31,1106,0,36,98,0,0,1002,21,125,20,4,20,1105,1,46,104,999,1105,1,46,1101,1000,1,20,4,20,1105,1,46,98,99", 7, 999, ), ( "3,21,1008,21,8,20,1005,20,22,107,8,21,20,1006,20,31,1106,0,36,98,0,0,1002,21,125,20,4,20,1105,1,46,104,999,1105,1,46,1101,1000,1,20,4,20,1105,1,46,98,99", 8, 1000, ), ( "3,21,1008,21,8,20,1005,20,22,107,8,21,20,1006,20,31,1106,0,36,98,0,0,1002,21,125,20,4,20,1105,1,46,104,999,1105,1,46,1101,1000,1,20,4,20,1105,1,46,98,99", 9, 1001, ), ] for data, data_input, result in datas: with self.subTest(data=data): p = Program(data) p.send_input(data_input) p.execute() self.assertEqual(next(p), result)
def main(): data = sys.stdin.readline() p = Program(data) p.send_input(1) p.execute() print(list(p))