Cudoviste

This commit is contained in:
2023-06-26 13:36:36 +02:00
parent 0361e789a2
commit a78dd59e7d

28
cudoviste.py Normal file
View File

@@ -0,0 +1,28 @@
def get_square(grid: list, upper_left: tuple) -> list:
square = []
for point in [(0, 0), (1, 0), (0, 1), (1, 1)]:
square.append(grid[upper_left[0] + point[0]][upper_left[1] + point[1]])
return square
def count_parking_spaces(grid: list, amount_of_car_crush: int) -> int:
rows, cols = len(grid), len(grid[0])
total = 0
for point in [(r, c) for r in range(rows - 1) for c in range(cols - 1)]:
square = get_square(grid, point)
if "#" in square:
continue
elif square.count("X") == amount_of_car_crush:
total += 1
return total
r, c = map(int, input().split())
grid = []
for i in range(r):
s = list(input().strip())
grid.append(s)
for i in range(5):
print(count_parking_spaces(grid, i))