Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions flower-field/flower_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,12 @@ def _calc_surrounding_flowers(i_row: int, i_col: int, garden: list[str]) -> int:
:returns: Number of adjacent flowers (0–8).
:rtype: int
"""
total: list[int] = [0]
# Only compute neighbors for empty squares; flowers are preserved by caller.
if garden[i_row][i_col] == " ":
# Count flowers all around current position
total = [
_process_cell(i_row, offset_row, i_col, offset_col, garden)
for offset_row, offset_col in COORDINATES
]

return sum(total)
if garden[i_row][i_col] != " ":
return 0
return sum(
_process_cell(i_row, offset_row, i_col, offset_col, garden)
for offset_row, offset_col in COORDINATES
)


def _process_cell(i_row, offset_row, i_col, offset_col, garden) -> int:
Expand Down