예제 #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_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])
예제 #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_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)
예제 #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
#!/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]}")
예제 #11
0
def part1(code):
    chall = CPU(False)
    chall.run(code)
    chall.input(1)
    print(f"Part 1: {chall.e_output[-1]}")
    del chall