for y, line in enumerate(text.splitlines()): | for y, line in enumerate(text.splitlines()): | ||||
for x, cell in enumerate(line): | for x, cell in enumerate(line): | ||||
grid[complex(x, y)] = cell | grid[complex(x, y)] = cell | ||||
return grid | |||||
return grid, x + 1, y + 1 | |||||
def shortest_path(start, end, move): | def shortest_path(start, end, move): |
import sys | |||||
from math import prod | |||||
def slide(step): | |||||
dx, dy = step | |||||
seen, x, y = 0, 0, 0 | |||||
while y + dy < height: | |||||
x += dx | |||||
y += dy | |||||
seen += grid[y][x % width] == '#' | |||||
return seen | |||||
grid = sys.stdin.read().splitlines() | |||||
height = len(grid) | |||||
width = len(grid[0]) | |||||
print(slide((3, 1))) | |||||
print(prod(map(slide, [(1, 1), (3, 1), (5, 1), (7, 1), (1, 2)]))) |