🎉」 init(2025): day 1

This commit is contained in:
2025-12-01 11:25:06 +01:00
commit 6306ab23d1
52 changed files with 2012 additions and 0 deletions

38
2024/day04/part2.py Normal file
View File

@@ -0,0 +1,38 @@
# sorry i gave up.
import os
import os.path
target = "XMAS"
def check_x(grid, x, y):
if (x not in range(1, len(grid[0]) - 1) or y not in range(1, len(grid) - 1)):
return (0)
str = grid[y - 1][x - 1] + grid[y + 1][x + 1]
if (str not in "SMS"):
return (0)
str = grid[y + 1][x - 1] + grid[y - 1][x + 1]
if (str not in "SMS"):
return (0)
return (1)
def count_xmas(grid):
res = 0
for y in range(len(grid)):
for x in range(len(grid[0])):
if (grid[y][x] == 'A'):
res += check_x(grid, x, y)
return (res)
def main():
file_path = "./input.txt"
if (os.path.isfile(file_path)):
content = open(file_path, "r").read()
else:
content = "MMMSXXMASM\nMSAMXMSMSA\nAMXSXMAAMM\nMSAMASMSMX\nXMASAMXAMM\nXXAMMXXAMA\nSMSMSASXSS\nSAXAMASAAA\nMAMMMXMMMM\nMXMXAXMASX"
grid = content.split('\n')
print(count_xmas(grid))
if __name__ == '__main__':
main()