Skip to content

Create 0283-move-zeroes.md - #55

Open
naoto-iwase wants to merge 1 commit into
mainfrom
0283-move-zeroes
Open

Create 0283-move-zeroes.md#55
naoto-iwase wants to merge 1 commit into
mainfrom
0283-move-zeroes

Conversation

@naoto-iwase

Copy link
Copy Markdown
Owner

return nothing, modify nums in-place instead.
"""
def swap(index1, index2):
nums[index1], nums[index2] = nums[index2], nums[index1]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

自分はしませんでしたが、このように swap 処理を関数に切り出す方が for 文の中の見通しがよさそうだと感じました。好みかもしれませんが。

swap_target_index = 0
for i in range(len(nums)):
if nums[i] != 0:
swap(i, swap_target_index)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ただの感想になりますが、swap_target_index <= i なので swap(swap_target_index, i) と書くのも自然なのかなと少し思いました。ただどちらが自然なのか、それとも意識しなくてもいいのか、わかりませんでした。

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.

ありがとうございます。

自分もそこで迷いました。iが主役で、swap_target_indexが脇役のように感じたのでこの順序を採用しましたが、自分もどちらがより自然かわからなかったです。

- [コメント集](https://docs.google.com/document/d/11HV35ADPo9QxJOpJQ24FcZvtvioli770WWdZZDaLOfg/edit?tab=t.0#heading=h.v62rdhwkdymb)
- https://discord.com/channels/1084280443945353267/1235829049511903273/1276579345099526267
- > まとめて 0 fill は、loop unrolling できたりするのでちょっと嬉しいこともあるでしょう。
- https://ja.wikipedia.org/wiki/%E3%83%AB%E3%83%BC%E3%83%97%E5%B1%95%E9%96%8B

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

キーワードからいろいろ調べられていて素晴らしいと思いました。自分は loop unrolling を初めて聞いたので調べてみようと思います。

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