Skip to content

Commit 767aa40

Browse files
Apply suggestions from code review
Co-authored-by: Tianyi Zheng <[email protected]>
1 parent 08c2256 commit 767aa40

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

other/word_search.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def insert_north(self, word: str, rows: list[int], cols: list[int]) -> None:
6666
self.board[row - i][col] = word[i]
6767
return
6868

69-
def insert_north_east(self, word: str, rows: list[int], cols: list[int]) -> None:
69+
def insert_northeast(self, word: str, rows: list[int], cols: list[int]) -> None:
7070
"""
7171
>>> ws = WordSearch(WORDS, 3, 3)
7272
>>> ws.insert_north_east("cat", [2], [0])
@@ -99,7 +99,7 @@ def insert_north_east(self, word: str, rows: list[int], cols: list[int]) -> None
9999
self.board[row - i][col + i] for i in range(word_length)
100100
]
101101
if all(letter is None for letter in letters_diagonal_left):
102-
# Successful, insert the word north
102+
# Successful, insert the word northeast
103103
for i in range(word_length):
104104
self.board[row - i][col + i] = word[i]
105105
return
@@ -131,12 +131,12 @@ def insert_east(self, word: str, rows: list[int], cols: list[int]) -> None:
131131
# to the right of the column that will be overwritten
132132
letters_left = [self.board[row][col + i] for i in range(word_length)]
133133
if all(letter is None for letter in letters_left):
134-
# Successful, insert the word north
134+
# Successful, insert the word east
135135
for i in range(word_length):
136136
self.board[row][col + i] = word[i]
137137
return
138138

139-
def insert_south_east(self, word: str, rows: list[int], cols: list[int]) -> None:
139+
def insert_southeast(self, word: str, rows: list[int], cols: list[int]) -> None:
140140
"""
141141
>>> ws = WordSearch(WORDS, 3, 3)
142142
>>> ws.insert_south_east("cat", [0], [0])
@@ -153,13 +153,13 @@ def insert_south_east(self, word: str, rows: list[int], cols: list[int]) -> None
153153
word_length = len(word)
154154
# Attempt to insert the word into each row and when successful, exit
155155
for row in rows:
156-
# Check if there is space for the word above the row
156+
# Check if there is space for the word below the row
157157
if word_length + row > self.height:
158158
continue
159159

160160
# Attempt to insert the word into each column
161161
for col in cols:
162-
# Check if there is space to the right of the word as well as above
162+
# Check if there is space to the right of the word as well as below
163163
if word_length + col > self.width:
164164
continue
165165

@@ -169,7 +169,7 @@ def insert_south_east(self, word: str, rows: list[int], cols: list[int]) -> None
169169
self.board[row + i][col + i] for i in range(word_length)
170170
]
171171
if all(letter is None for letter in letters_diagonal_left):
172-
# Successful, insert the word north
172+
# Successful, insert the word southeast
173173
for i in range(word_length):
174174
self.board[row + i][col + i] = word[i]
175175
return
@@ -206,7 +206,7 @@ def insert_south(self, word: str, rows: list[int], cols: list[int]) -> None:
206206
self.board[row + i][col] = word[i]
207207
return
208208

209-
def insert_south_west(self, word: str, rows: list[int], cols: list[int]) -> None:
209+
def insert_southwest(self, word: str, rows: list[int], cols: list[int]) -> None:
210210
"""
211211
>>> ws = WordSearch(WORDS, 3, 3)
212212
>>> ws.insert_south_west("cat", [0], [2])
@@ -223,13 +223,13 @@ def insert_south_west(self, word: str, rows: list[int], cols: list[int]) -> None
223223
word_length = len(word)
224224
# Attempt to insert the word into each row and when successful, exit
225225
for row in rows:
226-
# Check if there is space for the word above the row
226+
# Check if there is space for the word below the row
227227
if word_length + row > self.height:
228228
continue
229229

230230
# Attempt to insert the word into each column
231231
for col in cols:
232-
# Check if there is space to the right of the word as well as above
232+
# Check if there is space to the left of the word as well as below
233233
if word_length > col + 1:
234234
continue
235235

@@ -239,7 +239,7 @@ def insert_south_west(self, word: str, rows: list[int], cols: list[int]) -> None
239239
self.board[row + i][col - i] for i in range(word_length)
240240
]
241241
if all(letter is None for letter in letters_diagonal_left):
242-
# Successful, insert the word north
242+
# Successful, insert the word southwest
243243
for i in range(word_length):
244244
self.board[row + i][col - i] = word[i]
245245
return
@@ -271,12 +271,12 @@ def insert_west(self, word: str, rows: list[int], cols: list[int]) -> None:
271271
# to the left of the column that will be overwritten
272272
letters_left = [self.board[row][col - i] for i in range(word_length)]
273273
if all(letter is None for letter in letters_left):
274-
# Successful, insert the word north
274+
# Successful, insert the word west
275275
for i in range(word_length):
276276
self.board[row][col - i] = word[i]
277277
return
278278

279-
def insert_north_west(self, word: str, rows: list[int], cols: list[int]) -> None:
279+
def insert_northwest(self, word: str, rows: list[int], cols: list[int]) -> None:
280280
"""
281281
>>> ws = WordSearch(WORDS, 3, 3)
282282
>>> ws.insert_north_west("cat", [2], [2])
@@ -299,7 +299,7 @@ def insert_north_west(self, word: str, rows: list[int], cols: list[int]) -> None
299299

300300
# Attempt to insert the word into each column
301301
for col in cols:
302-
# Check if there is space to the right of the word as well as above
302+
# Check if there is space to the left of the word as well as above
303303
if word_length > col + 1:
304304
continue
305305

@@ -309,7 +309,7 @@ def insert_north_west(self, word: str, rows: list[int], cols: list[int]) -> None
309309
self.board[row - i][col - i] for i in range(word_length)
310310
]
311311
if all(letter is None for letter in letters_diagonal_left):
312-
# Successful, insert the word north
312+
# Successful, insert the word northwest
313313
for i in range(word_length):
314314
self.board[row - i][col - i] = word[i]
315315
return

0 commit comments

Comments
 (0)