Solve day4
This commit is contained in:
28
day4/part1.py
Normal file
28
day4/part1.py
Normal file
@@ -0,0 +1,28 @@
|
||||
FILE = "input.txt"
|
||||
|
||||
options = [
|
||||
(-1, -1), (-1, 0), (0, -1), (1, 1), (1, 0), (0, 1), (-1, 1), (1, -1)
|
||||
]
|
||||
|
||||
def main():
|
||||
accessible = 0
|
||||
grid = [list(line.strip()) for line in open(FILE)]
|
||||
for i in range(len(grid)):
|
||||
for j in range(len(grid[0])):
|
||||
if grid[i][j] != '@': continue
|
||||
nearby = [
|
||||
(i + x, j + y)
|
||||
for (x, y) in options
|
||||
if 0 <= i+x < len(grid) and 0 <= j+y < len(grid[0])
|
||||
]
|
||||
nearbyRolls = [
|
||||
grid[x][y]
|
||||
for (x, y) in nearby
|
||||
if grid[x][y] == '@'
|
||||
]
|
||||
if len(nearbyRolls) < 4: accessible += 1
|
||||
return accessible
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(main())
|
||||
Reference in New Issue
Block a user