30 lines
877 B
Python
Raw Normal View History

# SPDX-License-Identifier: MIT
# Copyright (c) 2019 Akumatic
#
# https://adventofcode.com/2019/day/2
2019-12-02 10:57:18 +01:00
import sys, os
sys.path.insert(1, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import intcode
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(",")]
def part1(vals: list) -> int:
2019-12-02 10:57:18 +01:00
memory = vals.copy()
memory[1], memory[2] = 12, 2
return intcode.getOutput(memory)
2019-12-02 10:57:18 +01:00
def part2(vals: list) -> int:
2019-12-02 10:57:18 +01:00
for noun in range(100):
for verb in range(100):
memory = vals.copy()
memory[1], memory[2] = noun, verb
if intcode.getOutput(memory) == 19690720:
2019-12-02 10:57:18 +01:00
return 100 * noun + verb
if __name__ == "__main__":
vals = readFile()
print(f"Part 1: {part1(vals)}")
print(f"Part 2: {part2(vals)}")