문제
코드
def detect_mine(ground, scope):
size = len(ground)
index = {
'x': 0,
'y': 0
}
result = 0
while True:
sum = 0
for x in range(index['y'], index['y'] + scope):
for y in range(index['x'], index['x'] + scope):
if ground[y][x]:
sum += 1
result = max(result, sum)
if index['x'] + scope == size:
if index['y'] + scope == size:
return result
index['x'] = 0
index['y'] += 1
else:
index['x'] += 1
if __name__ == '__main__':
matrix = [
[1, 0, 0, 1, 0],
[0, 1, 0, 0, 1],
[0, 0, 0, 1, 0],
[0, 0, 0, 0, 0],
[0, 0, 1, 0, 0],
]
print(detect_mine(matrix, 3))
Reference
제주 코딩 베이스 캠프 코딩 페스티벌 python 100제