mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-26 21:30:31 +01:00
Implement day 17 part 1
This commit is contained in:
26
2019/aoc2019/day17.py
Normal file
26
2019/aoc2019/day17.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
from typing import TextIO
|
||||||
|
|
||||||
|
from aoc2019.intcode import Computer, read_program
|
||||||
|
|
||||||
|
|
||||||
|
def part1(data: TextIO) -> int:
|
||||||
|
computer = Computer(read_program(data))
|
||||||
|
|
||||||
|
computer.run()
|
||||||
|
|
||||||
|
output = ''.join(chr(c) for c in computer.output)
|
||||||
|
|
||||||
|
tiles = set()
|
||||||
|
|
||||||
|
for y, line in enumerate(output.splitlines()):
|
||||||
|
for x, c in enumerate(line):
|
||||||
|
if c == '#':
|
||||||
|
tiles.add((x, y))
|
||||||
|
|
||||||
|
total = 0
|
||||||
|
|
||||||
|
for x, y in tiles:
|
||||||
|
if (x - 1, y) in tiles and (x + 1, y) in tiles and (x, y - 1) in tiles and (x, y + 1) in tiles:
|
||||||
|
total += x * y
|
||||||
|
|
||||||
|
return total
|
||||||
Reference in New Issue
Block a user