mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
2019 day 19 part 1
This commit is contained in:
21
2019/aoc2019/day19.py
Normal file
21
2019/aoc2019/day19.py
Normal file
@@ -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))
|
||||||
Reference in New Issue
Block a user