diff options
author | Marvin Borner | 2024-12-04 06:35:16 +0100 |
---|---|---|
committer | Marvin Borner | 2024-12-04 06:35:24 +0100 |
commit | 06553af16d4726fa6619b8d4042823da5c484bfa (patch) | |
tree | 1f89e52c2caedd2aeeda59e7e763b3e18f49a591 /2024 | |
parent | 7e41ec6dbccda7fbc483faa5f28a94319abb46b3 (diff) |
IHATEPYTHON[-1]
Diffstat (limited to '2024')
-rwxr-xr-x | 2024/04/solve.py | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/2024/04/solve.py b/2024/04/solve.py new file mode 100755 index 0000000..77c9419 --- /dev/null +++ b/2024/04/solve.py @@ -0,0 +1,127 @@ +#!/bin/env python + + +L = [l.strip() for l in open("input").readlines()] + + +# AAAAAAAAAAAAAAAAAH PYTHON WHY DO YOU SUPPORT -1 INDEX +# THIS COST ME 20 MINUTES +def get(l, idx): + if idx >= len(l) or idx < 0: + return "." + return l[idx] + + +def part1(): + res = 0 + + for y in range(len(L)): + for x in range(len(L[y])): + # horizontal + if ( + get(get(L, y), x) == "X" + and get(get(L, y), x + 1) == "M" + and get(get(L, y), x + 2) == "A" + and get(get(L, y), x + 3) == "S" + ): + res += 1 + + # horizontal inversed + if ( + get(get(L, y), x) == "S" + and get(get(L, y), x + 1) == "A" + and get(get(L, y), x + 2) == "M" + and get(get(L, y), x + 3) == "X" + ): + res += 1 + + # diagonal right + if ( + get(get(L, y), x) == "X" + and get(get(L, y + 1), x + 1) == "M" + and get(get(L, y + 2), x + 2) == "A" + and get(get(L, y + 3), x + 3) == "S" + ): + res += 1 + + # diagonal right inversed + if ( + get(get(L, y), x) == "S" + and get(get(L, y + 1), x + 1) == "A" + and get(get(L, y + 2), x + 2) == "M" + and get(get(L, y + 3), x + 3) == "X" + ): + res += 1 + + # vertical + if ( + get(get(L, y), x) == "X" + and get(get(L, y + 1), x) == "M" + and get(get(L, y + 2), x) == "A" + and get(get(L, y + 3), x) == "S" + ): + res += 1 + + # vertical inversed + if ( + get(get(L, y), x) == "S" + and get(get(L, y + 1), x) == "A" + and get(get(L, y + 2), x) == "M" + and get(get(L, y + 3), x) == "X" + ): + res += 1 + + # diagonal left + if ( + get(get(L, y), x) == "X" + and get(get(L, y + 1), x - 1) == "M" + and get(get(L, y + 2), x - 2) == "A" + and get(get(L, y + 3), x - 3) == "S" + ): + res += 1 + + # diagonal left inversed + if ( + get(get(L, y), x) == "S" + and get(get(L, y + 1), x - 1) == "A" + and get(get(L, y + 2), x - 2) == "M" + and get(get(L, y + 3), x - 3) == "X" + ): + res += 1 + print(res) + + +def part2(): + res = 0 + + for y in range(len(L)): + for x in range(len(L[y])): + if ( + ( + get(get(L, y), x) == "S" + and get(get(L, y + 1), x + 1) == "A" + and get(get(L, y + 2), x + 2) == "M" + ) + or ( + get(get(L, y), x) == "M" + and get(get(L, y + 1), x + 1) == "A" + and get(get(L, y + 2), x + 2) == "S" + ) + ) and ( + ( + get(get(L, y), x + 2) == "S" + and get(get(L, y + 1), x + 1) == "A" + and get(get(L, y + 2), x) == "M" + ) + or ( + get(get(L, y), x + 2) == "M" + and get(get(L, y + 1), x + 1) == "A" + and get(get(L, y + 2), x) == "S" + ) + ): + res += 1 + print(res) + + +part1() +part2() |