<filename>2020/3a.py
#!/usr/bin/env python3

from pathlib import Path

slope = 3, 1

class Map:

    def __init__(self, rows):
        self.w = len(rows[0])
        self.rows = rows

    def tree(self, x, y):
        return '#' == self.rows[y][x % self.w]

def main():
    m = Map(Path('input', '3').read_text().splitlines())
    xy = [0, 0]
    trees = 0
    try:
        while True:
            for i in range(2):
                xy[i] += slope[i]
            trees += m.tree(*xy)
    except IndexError:
        print(trees)

if '__main__' == __name__:
    main()

<filename>2020/3a.py
#!/usr/bin/env python3

from pathlib import Path

slope = 3, 1

class Map:

    def __init__(self, rows):
        self.w = len(rows[0])
        self.rows = rows

    def tree(self, x, y):
        return '#' == self.rows[y][x % self.w]

def main():
    m = Map(Path('input', '3').read_text().splitlines())
    xy = [0, 0]
    trees = 0
    try:
        while True:
            for i in range(2):
                xy[i] += slope[i]
            trees += m.tree(*xy)
    except IndexError:
        print(trees)

if '__main__' == __name__:
    main()

#!/usr/bin/env python3