Files
aoc/2025/04/part1.py

43 lines
1.0 KiB
Python

import os
if (os.path.isfile("./input")):
input = open("./input", "r").read()
else:
input = "..@@.@@@@.\n@@@.@.@.@@\n@@@@@.@.@@\n@.@@@@..@.\n@@.@@@@.@@\n.@@@@@@@.@\n.@.@.@.@@@\n@.@@@.@@@@\n.@@@@@@@@.\n@.@.@@@.@."
map = input.split('\n')
if (map[-1] == ""):
map.pop()
for i in range(len(map)):
map[i] = "." + map[i] + "."
map.append("." * len(map[0]))
map.insert(0, "." * len(map[0]))
r = 0
for y in range(len(map)):
for x in range(len(map[y])):
if map[y][x] == "@":
c = 0
if (map[y+1][x+1] == "@"):
c += 1
if (map[y+1][x] == "@"):
c += 1
if (map[y+1][x-1] == "@"):
c += 1
if (map[y][x+1] == "@"):
c += 1
if (map[y][x-1] == "@"):
c += 1
if (map[y-1][x+1] == "@"):
c += 1
if (map[y-1][x] == "@"):
c += 1
if (map[y-1][x-1] == "@"):
c += 1
if (c < 4):
r += 1
print(r)