ボウリングプログラム - #3
Open
hiro23900 wants to merge 5 commits into
Open
Conversation
yoshitsugu
reviewed
Aug 10, 2026
Comment on lines
+19
to
+41
| if i <= 8 | ||
| if frame[0] == 10 && frames[i + 1][0] == 10 | ||
| 10 + 10 + frames[i + 2][0] | ||
| elsif frame[0] == 10 && frames[i + 1][0] != 10 | ||
| 10 + frames[i + 1].sum | ||
| elsif frame.sum == 10 | ||
| 10 + frames[i + 1][0] | ||
| else | ||
| frame.sum | ||
| end | ||
| elsif i == 9 | ||
| if frame[0] == 10 && frames[10][0] == 10 | ||
| 10 + 10 + frames[11].sum | ||
| elsif frame[0] == 10 && frames[10][0] != 10 | ||
| 10 + frames[10].sum | ||
| elsif frame.sum == 10 | ||
| 10 + frames[10][0] | ||
| else | ||
| frame.sum | ||
| end | ||
| else | ||
| 0 | ||
| end |
There was a problem hiding this comment.
このあたり、もうちょっとロジックを整理してシンプルに書けるといいかなと思います。
ガード節による早期return(next)なども使うとよいです。
まず、i >= 9 のときは、10フレーム目の処理としてすべてたすだけです。プラクティスにも書いてありますね。
point = frames[9..].flatten.sumそれで、i <= 8 のときはとりあえずframe.sumはたすことになり、スペアやストライクのときだけボーナス計算になります。
point = frames[0..8].map.with_index do |frame. i|
result = frame.sum
next result if frame.sum != 10 # スペアでもストライクでもないとき
# ここ以降はスペア、もしくはストライクになるこのあたりヒントに、もう少し整理してみてください。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.