Browse Source

2020/3

master
Roderic Day 4 years ago
parent
commit
6472f7c8e1
2 changed files with 21 additions and 1 deletions
  1. +1
    -1
      toolkit.py
  2. +20
    -0
      y2020/p03.py

+ 1
- 1
toolkit.py View File

@@ -28,7 +28,7 @@ def read_image(text):
for y, line in enumerate(text.splitlines()):
for x, cell in enumerate(line):
grid[complex(x, y)] = cell
return grid
return grid, x + 1, y + 1


def shortest_path(start, end, move):

+ 20
- 0
y2020/p03.py View File

@@ -0,0 +1,20 @@
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)])))

Loading…
Cancel
Save