2019 Day 13 Part 2; intcode as class; intcode_test to assure functionality; changed old code to adapt intcode computer as object
This commit is contained in:
@ -5,24 +5,24 @@
|
||||
|
||||
import sys, os
|
||||
sys.path.insert(1, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
import intcode
|
||||
import intcode, intcode_test
|
||||
|
||||
def readFile() -> list:
|
||||
with open(f"{__file__.rstrip('code.py')}input.txt", "r") as f:
|
||||
return [int(num) for num in f.readline().split(",")]
|
||||
|
||||
def part1(vals: list) -> int:
|
||||
return intcode.getOutput(vals.copy(), input=1)
|
||||
def part1(pc: intcode.Computer) -> int:
|
||||
pc.reset(input=1)
|
||||
pc.run()
|
||||
return pc.data[0]
|
||||
|
||||
def part2(vals: list) -> int:
|
||||
return intcode.getOutput(vals.copy(), input=2)
|
||||
|
||||
def test():
|
||||
assert intcode.getOutput([104,1125899906842624,99]) == 1125899906842624
|
||||
assert len(str(intcode.getOutput([1102,34915192,34915192,7,4,7,99,0]))) == 16
|
||||
def part2(pc: intcode.Computer) -> int:
|
||||
pc.reset(input=2)
|
||||
pc.run()
|
||||
return pc.data[0]
|
||||
|
||||
if __name__ == "__main__":
|
||||
test()
|
||||
vals = readFile()
|
||||
print(f"Part 1: {part1(vals)}")
|
||||
print(f"Part 2: {part2(vals)}")
|
||||
intcode_test.test_09()
|
||||
pc = intcode.Computer(readFile())
|
||||
print(f"Part 1: {part1(pc)}")
|
||||
print(f"Part 2: {part2(pc)}")
|
Reference in New Issue
Block a user