Skip to content

Rotting Oranges#91

Open
Yuto729 wants to merge 1 commit into
mainfrom
rotting-oranges
Open

Rotting Oranges#91
Yuto729 wants to merge 1 commit into
mainfrom
rotting-oranges

Conversation

@Yuto729

@Yuto729 Yuto729 commented Jul 21, 2026

Copy link
Copy Markdown
Owner

解く問題

Rotting Oranges

次に解く問題

Repository owner deleted a comment from github-actions Bot Jul 21, 2026
Comment thread rotting-oranges/main.md
fresh_count = 0
for i in range(m):
for j in range(n):
if grid[i][j] == 2:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 と 2 がマジックナンバーになっているのが気になりました。 FRESH と ROTTING などの定数に置くと良いと思いました。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そちらの方がわかりやすいですね!

Comment thread rotting-oranges/main.md
minutes += 1
for r, c in current_level:
for dr, dc in direction:
next_r, next_c = r + dr, c + dc

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 行で複数の変数に代入しても、あまり読みやすくならないと思います。変数の代入は 1 行ずつ行ったほうが良いと思います。

Comment thread rotting-oranges/main.md
minutes += 1
for r, c in rotten_oranges:
for dr, dc in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
if r + dr < 0 or len(grid) <= r + dr or c + dc < 0 or len(grid[0]) <= c + dc:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Step 1 のように変数に置いたほうが、見通しが良くなると思いました。

next_r = r + dr
next_c = c + dc

Comment thread rotting-oranges/main.md
minutes += 1
for r, c in rotten_oranges:
for dr, dc in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
if r + dr < 0 or len(grid) <= r + dr or c + dc < 0 or len(grid[0]) <= c + dc:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Step 1 のように数直線上に一直線になるように書いたほうが、見通しが良くなると思いました。

if not (0 <= r + dr < len(grid) and 0 <= c + dc < len(grid[0])):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants