Esempio n. 1
0
 def test_part2_b_FAIL(self):
     code = [3, 9, 7, 9, 10, 9, 4, 9, 99, -1, 8]
     chall = CPU(False)
     chall.run(code)
     chall.input(8)
     chall.clean()
     self.assertEqual(chall.e_output, [0])
Esempio n. 2
0
 def test_part1_a(self):
     chall = CPU(False)
     code = [3, 0, 4, 0, 99]
     chall.run(code)
     chall.input(55)
     chall.clean()
     self.assertEqual(chall.e_output, [55])
Esempio n. 3
0
 def test_part2_d_FAIL(self):
     code = [3, 3, 1107, -1, 8, 3, 4, 3, 99]
     chall = CPU(False)
     chall.run(code)
     chall.input(8)
     chall.clean()
     self.assertEqual(chall.e_output, [0])
Esempio n. 4
0
 def test_part2_e_FAIL(self):
     code = [3, 12, 6, 12, 15, 1, 13, 14, 13, 4, 13, 99, -1, 0, 1, 9]
     chall = CPU(False)
     chall.run(code)
     chall.input(0)
     chall.clean()
     self.assertEqual(chall.e_output, [0])
Esempio n. 5
0
 def test_part1_b(self):
     chall = CPU(False)
     code = [1002, 4, 3, 4, 33]
     chall.run(code)
     chall.input(55)
     chall.clean()
     self.assertEqual(chall.code[4], 99)
Esempio n. 6
0
 def test_part2_b_PASS(self):
     """
     3,9,7,9,10,9,4,9,99,-1,8 - Using position mode, consider whether the input is less than 8; output 1 (if it is) or 0 (if it is not).
     """
     code = [3, 9, 7, 9, 10, 9, 4, 9, 99, -1, 8]
     chall = CPU(False)
     chall.run(code)
     chall.input(7)
     chall.clean()
     self.assertEqual(chall.e_output, [1])
Esempio n. 7
0
 def test_part2_d_PASS(self):
     """
     3,3,1107,-1,8,3,4,3,99 - Using immediate mode, consider whether the input is less than 8; output 1 (if it is) or 0 (if it is not).
     """
     code = [3, 3, 1107, -1, 8, 3, 4, 3, 99]
     chall = CPU(False)
     chall.run(code)
     chall.input(7)
     chall.clean()
     self.assertEqual(chall.e_output, [1])
Esempio n. 8
0
 def test_part2_e_PASS(self):
     """
     Here are some jump tests that take an input, then output 0 if the input was zero or 1 if the input was non-zero:
     (using position mode)
     """
     code = [3, 12, 6, 12, 15, 1, 13, 14, 13, 4, 13, 99, -1, 0, 1, 9]
     chall = CPU(False)
     chall.run(code)
     chall.input(1)
     chall.clean()
     self.assertEqual(chall.e_output, [1])
Esempio n. 9
0
 def test_part2_f_GT(self):
     """
     The above example program uses an input instruction to ask for a single number. 
     The program will then output 999 if the input value is below 8, 
     output 1000 if the input value is equal to 8, 
     or output 1001 if the input value is greater than 8.
     """
     code = [
         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
     ]
     chall = CPU(False)
     chall.run(code)
     chall.input(9)
     chall.clean()
     self.assertEqual(chall.e_output, [1001])
Esempio n. 10
0
def main():
    with open('data/2') as fh:
        lines = fh.readlines()
        for line in lines:
            code = line.split(',')

        cpu = CPU(False)
        cpu.run(code.copy())
        print(f"Part 1: {cpu.code[0]}")
        del cpu

        for a in range(0, 99):
            for b in range(0, 99):
                cpu = CPU(False)
                c = code.copy()
                c[1] = a
                c[2] = b
                cpu.run(c)
                x = cpu.code[0]
                if x == 19690720:
                    val = 100 * a + b
                    print(f"Part 2: {val} = {a},{b}")
                    return
                del cpu
Esempio n. 11
0
 def test_Day9_part_1c(self):
     chall = CPU(False)
     code = [104,1125899906842624,99]
     chall.run(code.copy())
     self.assertEqual(chall.e_output, [1125899906842624])
     del chall
Esempio n. 12
0
 def test_Day9_part_1b(self):
     chall = CPU(False)
     code = [1102,34915192,34915192,7,4,7,99,0]
     chall.run(code.copy())
     self.assertEqual(chall.e_output, [1219070632396864])
     del chall
Esempio n. 13
0
 def test_part2_a(self):
     chall = CPU(False)
     code = [99, 12, 2]
     err = chall.run(code)
     chall.clean()
     self.assertEqual(err, 1202)
Esempio n. 14
0
 def test_part1_d(self):
     chall = CPU(False)
     code = [1, 1, 1, 4, 99, 5, 6, 0, 99]
     chall.run(code)
     chall.clean()
     self.assertEqual(chall.code, [30, 1, 1, 4, 2, 5, 6, 0, 99])
Esempio n. 15
0
 def test_part1_a(self):
     chall = CPU(False)
     code = [1, 0, 0, 0, 99]
     chall.run(code)
     chall.clean()
     self.assertEqual(chall.code, [2, 0, 0, 0, 99])
Esempio n. 16
0
#!/usr/bin/env python3

from aoc2019 import CPU
import logging

if __name__ == "__main__":
    #logging.basicConfig(level=logging.DEBUG)
    chall = CPU(True)
    code = [
        109, 1, 204, -1, 1001, 100, 1, 100, 1008, 100, 16, 101, 1006, 101, 0,
        99
    ]
    chall.run(code.copy())
    print(chall.code)
    print(chall.e_output)
Esempio n. 17
0
File: 9.py Progetto: rgooler/AOC2019
def part1(code):
    chall = CPU(False)
    chall.run(code)
    print(f"Part 1: {chall.e_output}")
    del chall
Esempio n. 18
0
 def test_part1_c(self):
     chall = CPU(False)
     code = [2, 4, 4, 5, 99, 0]
     chall.run(code)
     chall.clean()
     self.assertEqual(chall.code, [2, 4, 4, 5, 99, 9801])
Esempio n. 19
0
 def test_Day9_part_1a(self):
     chall = CPU(False)
     code = [109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99]
     chall.run(code.copy())
     self.assertEqual(chall.e_output, code)
     del chall
Esempio n. 20
0
def part1(code):
    chall = CPU(False)
    chall.run(code)
    chall.input(1)
    print(f"Part 1: {chall.e_output[-1]}")
    del chall
Esempio n. 21
0
 def test_part1_b(self):
     chall = CPU(False)
     code = [2, 3, 0, 3, 99]
     chall.run(code)
     chall.clean()
     self.assertEqual(chall.code, [2, 3, 0, 6, 99])