def test_fifo() -> None: ic = Intcomputer([3, 9, 3, 10, 4, 9, 4, 10, 99, 0, 0]) ic.input(1) ic.input(2) ic.run() assert ic.output() == 1 assert ic.output() == 2
def test_eq() -> None: ic = Intcomputer([1108, 3, 3, 9, 1108, 3, 4, 11, 104, 0, 104, 0, 99]) ic.run() assert ic.output() == 1 assert ic.output() == 0
def test_lt() -> None: ic = Intcomputer([1107, 2, 3, 9, 1107, 3, 2, 11, 104, 0, 104, 0, 99]) ic.run() assert ic.output() == 1 assert ic.output() == 0
def test_jif() -> None: ic = Intcomputer( [1106, 0, 6, 104, 0, 99, 1106, 1, 12, 104, 1, 99, 104, 0, 99]) ic.run() assert ic.output() == 1
def test_out() -> None: ic = Intcomputer([4, 1, 99]) ic.run() assert ic.output() == 1
from intcomputer import Intcomputer with open("inputs.txt", "r+") as inputs: raw_intcode = ''.join(inputs.readlines()) intcode = [int(elt) for elt in raw_intcode.split(',')] intcom = Intcomputer(intcode) intcom.run() while(True): try: print("Output -->",intcom.output()) except StopIteration: print("Nothing to output") break