From 7718fc59c6e5076b91cb8cfcc82b7e031929212c Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Thu, 21 Oct 2021 08:05:22 +0200 Subject: [PATCH] 2019 day 19 part 1 --- 2019/aoc2019/day19.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 2019/aoc2019/day19.py diff --git a/2019/aoc2019/day19.py b/2019/aoc2019/day19.py new file mode 100644 index 0000000..484ad27 --- /dev/null +++ b/2019/aoc2019/day19.py @@ -0,0 +1,21 @@ +import copy +from itertools import product +from typing import TextIO + +from aoc2019.intcode import Computer, read_program + + +def query_position(x: int, y: int, computer: Computer) -> bool: + computer = copy.deepcopy(computer) + + computer.send_input(x) + computer.send_input(y) + computer.run() + + return computer.get_output() == 1 + + +def part1(data: TextIO) -> int: + computer = Computer(read_program(data)) + + return sum(1 for x, y in product(range(50), range(50)) if query_position(x, y, computer))