aboutsummaryrefslogtreecommitdiff
path: root/2023/21/solve.py
blob: df1787835fc2bb706ee0c60fd30a8564f7cf3398 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
L = {
    (i, j): c
    for (i, l) in enumerate(open("input").readlines())
    for (j, c) in enumerate(l.strip())
}


def solve1():
    LIM = 64

    res = 0
    s = [(i, j) for (i, j) in L if L[(i, j)] == "S"][0]
    q = [(s, 0)]
    v = set()
    while q:
        p, n = q.pop(0)
        if n == LIM + 1:
            continue

        for move in [(0, 1), (1, 0), (0, -1), (-1, 0)]:
            np = (p[0] + move[0], p[1] + move[1])
            if np not in L or np in v or L[np] == "#":
                continue
            q.append((np, n + 1))
            v.add(np)
            if n % 2:
                res += 1
    print(res)


solve1()