Пример #1
0
def main():
    memory = codes()
    for noun in range(99):
        for verb in range(99):
            ic = Intcode(memory)\
                .replace(1, noun)\
                .replace(2, verb)\
                .compute()
            total = ic.memory[0]
            if total == 19690720:
                print(100 * noun + verb)
                return
            elif total > 19690720:
                break
Пример #2
0
def main():
    comp = Intcode(codes())\
        .replace(1, 12)\
        .replace(2, 2)\
        .compute()
    print(comp.codes[0])
Пример #3
0
 def test_replace(self):
     ic = Intcode([0, 1, 2, 3, 4, 5])\
         .replace(2, 98)\
         .replace(4, 99)
     target = Intcode([0, 1, 98, 3, 99, 5])
     self.assertEqual(ic, target)
Пример #4
0
 def test_stores_memory_and_pointer(self):
     ic = Intcode([1, 2, 3], pointer=4)
     self.assertEqual(ic.pointer, 4)
     self.assertEqual(ic.memory, [1, 2, 3])
Пример #5
0
 def test_early_stop(self):
     ic = Intcode([1, 9, 10, 3, 2, 3, 11, 0, 99, 30, 40, 50])
     target = Intcode([3500, 9, 10, 70, 2, 3, 11, 0, 99, 30, 40, 50],
                      pointer=12,
                      done=True)
     self.assertEqual(ic.compute(), target)
Пример #6
0
 def test_compute(self):
     ic = Intcode([1, 1, 1, 4, 99, 5, 6, 0, 99])
     target = Intcode([30, 1, 1, 4, 2, 5, 6, 0, 99], pointer=12, done=True)
     self.assertEqual(ic.compute(), target)
Пример #7
0
 def test_simple_done(self):
     ic = Intcode([99, 1, 2, 3])
     target = Intcode([99, 1, 2, 3], pointer=4, done=True)
     self.assertEqual(ic.compute(), target)
Пример #8
0
 def test_simple_multiplication(self):
     ic = Intcode([2, 4, 4, 5, 99, 0])
     target = Intcode([2, 4, 4, 5, 99, 9801], pointer=8, done=True)
     self.assertEqual(ic.compute(), target)
Пример #9
0
 def test_simple_addition(self):
     ic = Intcode([1, 0, 5, 0, 99, 8])
     target = Intcode([9, 0, 5, 0, 99, 8], pointer=8, done=True)
     self.assertEqual(ic.compute(), target)