コード例 #1
0
ファイル: test_5.py プロジェクト: rgooler/AOC2019
 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])
コード例 #2
0
ファイル: test_5.py プロジェクト: rgooler/AOC2019
 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)
コード例 #3
0
ファイル: test_5.py プロジェクト: rgooler/AOC2019
 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])
コード例 #4
0
ファイル: test_5.py プロジェクト: rgooler/AOC2019
 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])
コード例 #5
0
ファイル: test_5.py プロジェクト: rgooler/AOC2019
 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])
コード例 #6
0
ファイル: test_5.py プロジェクト: rgooler/AOC2019
 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])
コード例 #7
0
ファイル: test_5.py プロジェクト: rgooler/AOC2019
 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])
コード例 #8
0
ファイル: test_5.py プロジェクト: rgooler/AOC2019
 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])
コード例 #9
0
ファイル: test_5.py プロジェクト: rgooler/AOC2019
 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])
コード例 #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
コード例 #11
0
ファイル: test_9.py プロジェクト: rgooler/AOC2019
 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
コード例 #12
0
ファイル: test_9.py プロジェクト: rgooler/AOC2019
 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
コード例 #13
0
ファイル: test_9.py プロジェクト: rgooler/AOC2019
 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
コード例 #14
0
 def test_part2_a(self):
     chall = CPU(False)
     code = [99, 12, 2]
     err = chall.run(code)
     chall.clean()
     self.assertEqual(err, 1202)
コード例 #15
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])
コード例 #16
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])
コード例 #17
0
ファイル: demo_cpu.py プロジェクト: rgooler/AOC2019
#!/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)
コード例 #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])
コード例 #19
0
def part1(code):
    chall = CPU(False)
    chall.run(code)
    chall.input(1)
    print(f"Part 1: {chall.e_output[-1]}")
    del chall
コード例 #20
0
ファイル: 9.py プロジェクト: rgooler/AOC2019
def part1(code):
    chall = CPU(False)
    chall.run(code)
    print(f"Part 1: {chall.e_output}")
    del chall
コード例 #21
0
#!/usr/bin/env python3

from aoc2019 import CPU

if __name__ == "__main__":
    chall = CPU(False)
    # Takes two numbers as input and adds them
    code = [3, 9, 3, 10, 1, 9, 10, 11, 99, 0, 0, 0]
    chall.code = code
    chall.eval()
    chall.input(input("Whats the first number? "))
    chall.input(input("Whats the second number? "))
    print(f"The answer is: {chall.code[-1]}")
コード例 #22
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])