Skip to content

Commit

Permalink
[프로그래머스] 이웃한 칸
Browse files Browse the repository at this point in the history
  • Loading branch information
ehdgua01 committed Sep 2, 2024
1 parent dc4855e commit a832d5b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions coding_test/programmers/neighbor_box.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
def solution(board, h, w):
positions = {
max(0, h - 1): [w],
min(len(board) - 1, h + 1): [w],
h: [max(0, w - 1), min(len(board) - 1, w + 1)],
}
return sum(
board[height][width] == board[h][w]
for height in positions
for width in positions[height]
if not (height == h and width == w)
)


def test_cases():
assert (
solution(
[
["blue", "red", "orange", "red"],
["red", "red", "blue", "orange"],
["blue", "orange", "red", "red"],
["orange", "orange", "red", "blue"],
],
3,
1,
)
== 2
)
assert (
solution(
[
["yellow", "green", "blue"],
["blue", "green", "yellow"],
["yellow", "blue", "blue"],
],
0,
1,
)
== 1
)

0 comments on commit a832d5b

Please sign in to comment.