diff options
author | Marvin Borner | 2023-12-21 11:46:49 +0100 |
---|---|---|
committer | Marvin Borner | 2023-12-21 11:46:49 +0100 |
commit | 942084cd25903dfee8ef51023113667f20a4fc8d (patch) | |
tree | 11fed6e8e8092453e7bbd03eac6b9eeb1a2370a5 | |
parent | b812ead13b15bb742159f77ba1b89d416cb41c50 (diff) |
part2?!?!!
-rw-r--r-- | 2023/21/solve.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/2023/21/solve.py b/2023/21/solve.py new file mode 100644 index 0000000..df17878 --- /dev/null +++ b/2023/21/solve.py @@ -0,0 +1,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() |