diff --git a/2024/day04/part2.py b/2024/day04/part2.py new file mode 100644 index 0000000..d354420 --- /dev/null +++ b/2024/day04/part2.py @@ -0,0 +1,21 @@ +import re + +text: str + +with open("input.txt") as f: + text = f.read() + +lines: list[str] = text.splitlines() + +total: int = 0 + +for line1, line2, line3 in zip(lines[0:-2], lines[1:-1], lines[2:]): + for i in range(0, len(line1) - 2): + if (line2[i + 1] == "A"): + total += (line1[i] == "M" and line3[i] == "M" and line1[i + 2] == "S" and line3[i + 2] == "S") + total += (line1[i] == "M" and line3[i] == "S" and line1[i + 2] == "M" and line3[i + 2] == "S") + total += (line1[i] == "S" and line3[i] == "S" and line1[i + 2] == "M" and line3[i + 2] == "M") + total += (line1[i] == "S" and line3[i] == "M" and line1[i + 2] == "S" and line3[i + 2] == "M") + + +print(total) \ No newline at end of file