2020-12-02 21:34:21 +01:00
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
# Copyright (c) 2019 Akumatic
|
|
|
|
#
|
|
|
|
# https://adventofcode.com/2019/day/2
|
2019-12-02 10:57:18 +01:00
|
|
|
|
2020-12-02 21:34:21 +01:00
|
|
|
import sys, os
|
|
|
|
sys.path.insert(1, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
2020-12-03 23:45:28 +01:00
|
|
|
import intcode, intcode_test
|
2020-12-02 21:34:21 +01:00
|
|
|
|
|
|
|
def readFile() -> list:
|
2019-12-02 21:39:49 +01:00
|
|
|
with open(f"{__file__.rstrip('code.py')}input.txt", "r") as f:
|
2019-12-02 10:57:18 +01:00
|
|
|
return [int(num) for num in f.readline().split(",")]
|
|
|
|
|
2020-12-03 23:45:28 +01:00
|
|
|
def part1(pc: intcode.Computer) -> int:
|
|
|
|
pc.data[1], pc.data[2] = 12, 2
|
|
|
|
pc.run()
|
|
|
|
return pc.data[0]
|
2019-12-02 10:57:18 +01:00
|
|
|
|
2020-12-03 23:45:28 +01:00
|
|
|
def part2(pc: intcode.Computer) -> int:
|
2019-12-02 10:57:18 +01:00
|
|
|
for noun in range(100):
|
|
|
|
for verb in range(100):
|
2020-12-03 23:45:28 +01:00
|
|
|
pc.reset()
|
|
|
|
pc.data[1], pc.data[2] = noun, verb
|
|
|
|
pc.run()
|
|
|
|
if pc.data[0] == 19690720:
|
2019-12-02 10:57:18 +01:00
|
|
|
return 100 * noun + verb
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2020-12-03 23:45:28 +01:00
|
|
|
intcode_test.test_02()
|
|
|
|
pc = intcode.Computer(readFile())
|
|
|
|
print(f"Part 1: {part1(pc)}")
|
|
|
|
print(f"Part 2: {part2(pc)}")
|