Skip to content

Commit

Permalink
Update line_safari.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Dec 3, 2024
1 parent a21a000 commit c643f2a
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions kyu_3/line_safari_is_that_a_line/line_safari.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def line(grid: list) -> bool:

def assert_x_has_rout(grid: list) -> bool:
"""
Make sure x has a valid route
Make sure x has a valid route.
:param grid:
:return:
"""
Expand All @@ -47,13 +47,13 @@ def assert_x_has_rout(grid: list) -> bool:
if char == 'X':
temp = []
# up
if row_i - 1 >= 0 and grid[row_i - 1][col_i] in 'X|+':
if row_i >= 1 and grid[row_i - 1][col_i] in 'X|+':
temp.append(True)
# down
if row_i + 1 < len(grid) and grid[row_i + 1][col_i] in 'X|+':
temp.append(True)
# left
if col_i - 1 >= 0 and row[col_i - 1] in 'X+-':
if col_i >= 1 and row[col_i - 1] in 'X+-':
temp.append(True)
# right
if col_i + 1 < len(row) and row[col_i + 1] in 'X+-':
Expand All @@ -67,11 +67,9 @@ def assert_x_has_rout(grid: list) -> bool:

def x_counter(grid: list) -> int:
"""
Counter number of X
Counter number of X.
:param grid: list
:return: int
"""
counter: int = 0
for row in grid:
counter += row.count('X')
counter: int = sum(row.count('X') for row in grid)
return counter

0 comments on commit c643f2a

Please sign in to comment.