From bd99e02d7bc159e43af780f92d5cb3315f0cf9dd Mon Sep 17 00:00:00 2001 From: shoma Date: Tue, 18 Nov 2025 10:13:47 +0900 Subject: [PATCH 01/11] =?UTF-8?q?=E3=82=AA=E3=83=96=E3=82=B8=E3=82=A7?= =?UTF-8?q?=E3=82=AF=E3=83=88=E6=8C=87=E5=90=91=E3=81=A7=E3=83=9C=E3=82=A6?= =?UTF-8?q?=E3=83=AA=E3=83=B3=E3=82=B0=E3=83=97=E3=83=AD=E3=82=B0=E3=83=A9?= =?UTF-8?q?=E3=83=A0=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 06.bowling_object/bowling.rb | 8 ++++++ 06.bowling_object/frame.rb | 24 ++++++++++++++++ 06.bowling_object/game.rb | 53 ++++++++++++++++++++++++++++++++++++ 06.bowling_object/shot.rb | 17 ++++++++++++ 4 files changed, 102 insertions(+) create mode 100644 06.bowling_object/bowling.rb create mode 100644 06.bowling_object/frame.rb create mode 100644 06.bowling_object/game.rb create mode 100644 06.bowling_object/shot.rb diff --git a/06.bowling_object/bowling.rb b/06.bowling_object/bowling.rb new file mode 100644 index 0000000000..951ad8b49f --- /dev/null +++ b/06.bowling_object/bowling.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +require_relative 'game' +require_relative 'frame' +require_relative 'shot' + +game = Game.new(ARGV[0]) +puts game.total_score diff --git a/06.bowling_object/frame.rb b/06.bowling_object/frame.rb new file mode 100644 index 0000000000..81d6e08cb2 --- /dev/null +++ b/06.bowling_object/frame.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require_relative 'shot' + +class Frame + attr_reader :first_shot + + def initialize(first_score, second_score = '0') + @first_shot = Shot.new(first_score) + @second_shot = Shot.new(second_score) + end + + def total_score + @first_shot.score + @second_shot.score + end + + def spare? + total_score == 10 && @first_shot.score != 10 + end + + def strike? + total_score == 10 && @first_shot.score == 10 + end +end diff --git a/06.bowling_object/game.rb b/06.bowling_object/game.rb new file mode 100644 index 0000000000..dfc64391fc --- /dev/null +++ b/06.bowling_object/game.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require_relative 'frame' + +class Game + def initialize(row_scores) + framed_scores = parse_scores(row_scores) + # Frameクラス内のfirst_shot, second_shotとは命名の法則が異なっており統一感は無いが、 + # ここでfirst_frame, second_frame・・・と宣言したら全体の記述が長くなり、 + # むしろ可読性が落ちると判断したので配列で宣言 + @frames = framed_scores.map do |score| + # 基本は10フレームだが、10フレーム目でスペアかストライクを出すと11フレーム生成される。 + # 得点計算の処理を単純にできるのでこうしている + Frame.new(*score) + end + end + + def total_score + total_score = 0 + frame_count = 10 + frame_count.times do |index| + frame = @frames[index] + total_score += frame.total_score + total_score += calc_strike_bounus(index) if frame.strike? + total_score += calc_spare_bounus(index) if frame.spare? + end + total_score + end + + private + + def parse_scores(row_scores) + scores = row_scores.split(',').flat_map do |score| + score == 'X' ? %w[X 0] : score + end + scores.each_slice(2).to_a + end + + def calc_strike_bounus(index) + next_index = index + 1 + after_the_next = next_index + 1 + if @frames[next_index].strike? + @frames[next_index].first_shot.score + @frames[after_the_next].first_shot.score + else + @frames[next_index].total_score + end + end + + def calc_spare_bounus(index) + next_index = index + 1 + @frames[next_index].first_shot.score + end +end diff --git a/06.bowling_object/shot.rb b/06.bowling_object/shot.rb new file mode 100644 index 0000000000..93720c7509 --- /dev/null +++ b/06.bowling_object/shot.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class Shot + attr_reader :score + + def initialize(string_score) + @score = to_int_score(string_score) + end + + private + + def to_int_score(string_score) + return 10 if string_score == 'X' + + string_score.to_i + end +end From e4d0de2c2705ea431931190a41eb9c1293ae1d69 Mon Sep 17 00:00:00 2001 From: shoma Date: Tue, 18 Nov 2025 10:14:27 +0900 Subject: [PATCH 02/11] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=B3?= =?UTF-8?q?=E3=83=BC=E3=83=89=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 06.bowling_object/test_bowling.rb | 64 +++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 06.bowling_object/test_bowling.rb diff --git a/06.bowling_object/test_bowling.rb b/06.bowling_object/test_bowling.rb new file mode 100644 index 0000000000..1d28be4ceb --- /dev/null +++ b/06.bowling_object/test_bowling.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +require_relative 'game' + +def main + test_bowling_return_139 + test_bowling_return_164 + test_bowling_return_107 + test_bowling_return_134 + test_bowling_return_144 + test_bowling_return_300 + test_bowling_return_292 + test_bowling_return_50 +end + +def test_bowling_return_139 + template_test_bowling('6,3,9,0,0,3,8,2,7,3,X,9,1,8,0,X,6,4,5', 139) +end + +def test_bowling_return_164 + template_test_bowling('6,3,9,0,0,3,8,2,7,3,X,9,1,8,0,X,X,X,X', 164) +end + +def test_bowling_return_107 + template_test_bowling('0,10,1,5,0,0,0,0,X,X,X,5,1,8,1,0,4', 107) +end + +def test_bowling_return_134 + template_test_bowling('6,3,9,0,0,3,8,2,7,3,X,9,1,8,0,X,X,0,0', 134) +end + +def test_bowling_return_144 + template_test_bowling('6,3,9,0,0,3,8,2,7,3,X,9,1,8,0,X,X,1,8', 144) +end + +def test_bowling_return_300 + template_test_bowling('X,X,X,X,X,X,X,X,X,X,X,X', 300) +end + +def test_bowling_return_292 + template_test_bowling('X,X,X,X,X,X,X,X,X,X,X,2', 292) +end + +def test_bowling_return_50 + template_test_bowling('X,0,0,X,0,0,X,0,0,X,0,0,X,0,0', 50) +end + +def template_test_bowling(input, expected) + game = Game.new(input) + puts "入力したスコア:#{input}" + puts "expected: #{expected}" + + total_score = game.total_score + puts "actual: #{total_score}" + + if total_score == expected + puts '正常' + else + puts '異常' + end + puts '' +end + +main From dcee9cb4d45554d45579c3217b84f9fe01654710 Mon Sep 17 00:00:00 2001 From: shoma Date: Tue, 25 Nov 2025 08:33:59 +0900 Subject: [PATCH 03/11] =?UTF-8?q?shot=E3=82=AF=E3=83=A9=E3=82=B9=E3=82=92?= =?UTF-8?q?=E3=82=88=E3=82=8A=E7=B0=A1=E6=BD=94=E3=81=AB=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=81=9F=E3=82=81=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 06.bowling_object/shot.rb | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/06.bowling_object/shot.rb b/06.bowling_object/shot.rb index 93720c7509..da9ee9ca12 100644 --- a/06.bowling_object/shot.rb +++ b/06.bowling_object/shot.rb @@ -4,14 +4,6 @@ class Shot attr_reader :score def initialize(string_score) - @score = to_int_score(string_score) - end - - private - - def to_int_score(string_score) - return 10 if string_score == 'X' - - string_score.to_i + @score = string_score == 'X' ? 10 : string_score.to_i end end From 5d983923542b49b9164cc5dfdfbd0503308f2dbb Mon Sep 17 00:00:00 2001 From: shoma Date: Tue, 25 Nov 2025 08:43:38 +0900 Subject: [PATCH 04/11] =?UTF-8?q?=E3=83=9C=E3=82=A6=E3=83=AA=E3=83=B3?= =?UTF-8?q?=E3=82=B0=E3=81=AE=E4=BB=95=E6=A7=98=E3=82=92=E6=AD=A3=E7=A2=BA?= =?UTF-8?q?=E3=81=AB=E8=A1=A8=E7=8F=BE=E3=81=99=E3=82=8B=E3=81=9F=E3=82=81?= =?UTF-8?q?=E3=81=AB=E4=BF=AE=E6=AD=A3&=E3=82=AF=E3=83=A9=E3=82=B9?= =?UTF-8?q?=E3=81=AE=E8=B2=AC=E5=8B=99=E3=81=AE=E8=A6=8B=E7=9B=B4=E3=81=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 06.bowling_object/frame.rb | 35 ++++++++++++++++++++++++----- 06.bowling_object/game.rb | 45 ++++++++++++++------------------------ 2 files changed, 46 insertions(+), 34 deletions(-) diff --git a/06.bowling_object/frame.rb b/06.bowling_object/frame.rb index 81d6e08cb2..f9fe26d13f 100644 --- a/06.bowling_object/frame.rb +++ b/06.bowling_object/frame.rb @@ -3,22 +3,47 @@ require_relative 'shot' class Frame - attr_reader :first_shot + attr_reader :first_shot, :second_shot, :third_shot + attr_writer :referable_frames - def initialize(first_score, second_score = '0') + def initialize(first_score, second_score, third_score = nil) @first_shot = Shot.new(first_score) @second_shot = Shot.new(second_score) + @third_shot = third_score.nil? ? nil : Shot.new(third_score) end def total_score - @first_shot.score + @second_shot.score + return [@first_shot.score, @second_shot.score, @third_shot.score].sum unless @third_shot.nil? + + total_score = [@first_shot.score, @second_shot.score].sum + total_score += strike_bounus if strike? + total_score += spare_bounus if spare? + total_score + end + + def strike_bounus + next_frame = @referable_frames[0] + after_the_next_frame = @referable_frames[1] + if next_frame.strike? + # 9フレーム目の場合 + return next_frame.first_shot.score + next_frame.second_shot.score if after_the_next_frame.nil? + + next_frame.first_shot.score + after_the_next_frame.first_shot.score + else + next_frame.first_shot.score + next_frame.second_shot.score + end + end + + def spare_bounus + next_index = 0 + @referable_frames[next_index].first_shot.score end def spare? - total_score == 10 && @first_shot.score != 10 + @first_shot.score + @second_shot.score == 10 && @first_shot.score != 10 end def strike? - total_score == 10 && @first_shot.score == 10 + @first_shot.score == 10 end end diff --git a/06.bowling_object/game.rb b/06.bowling_object/game.rb index dfc64391fc..9ca87b104a 100644 --- a/06.bowling_object/game.rb +++ b/06.bowling_object/game.rb @@ -9,45 +9,32 @@ def initialize(row_scores) # ここでfirst_frame, second_frame・・・と宣言したら全体の記述が長くなり、 # むしろ可読性が落ちると判断したので配列で宣言 @frames = framed_scores.map do |score| - # 基本は10フレームだが、10フレーム目でスペアかストライクを出すと11フレーム生成される。 - # 得点計算の処理を単純にできるのでこうしている Frame.new(*score) end + @frames.each_with_index do |frame, index| + # 9フレーム目であれば + if index.equal?(8) + frame.referable_frames = [@frames[index + 1]] + else + # 10フレーム目以外 + frame.referable_frames = [@frames[index + 1], @frames[index + 2]] unless index.equal?(9) + end + end end def total_score - total_score = 0 - frame_count = 10 - frame_count.times do |index| - frame = @frames[index] - total_score += frame.total_score - total_score += calc_strike_bounus(index) if frame.strike? - total_score += calc_spare_bounus(index) if frame.spare? - end - total_score + @frames.sum { |frame| frame.total_score } end private def parse_scores(row_scores) - scores = row_scores.split(',').flat_map do |score| - score == 'X' ? %w[X 0] : score + scores = [] + row_scores.split(',').each do |score| + scores.length < 18 && score == 'X' ? scores.push('X','0') : scores << score end - scores.each_slice(2).to_a - end - - def calc_strike_bounus(index) - next_index = index + 1 - after_the_next = next_index + 1 - if @frames[next_index].strike? - @frames[next_index].first_shot.score + @frames[after_the_next].first_shot.score - else - @frames[next_index].total_score - end - end - - def calc_spare_bounus(index) - next_index = index + 1 - @frames[next_index].first_shot.score + tenth_frame_scores = scores[18...scores.count] + framed_scores = scores[0..17].each_slice(2).to_a + framed_scores << tenth_frame_scores end end From 4fed4da1cfb45c92615ed516e0ff4f87b4be35bd Mon Sep 17 00:00:00 2001 From: shoma Date: Tue, 25 Nov 2025 08:48:19 +0900 Subject: [PATCH 05/11] =?UTF-8?q?=E6=9B=B8=E5=BC=8F=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 06.bowling_object/game.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/06.bowling_object/game.rb b/06.bowling_object/game.rb index 9ca87b104a..952a45dc76 100644 --- a/06.bowling_object/game.rb +++ b/06.bowling_object/game.rb @@ -23,7 +23,7 @@ def initialize(row_scores) end def total_score - @frames.sum { |frame| frame.total_score } + @frames.sum(&:total_score) end private @@ -31,7 +31,7 @@ def total_score def parse_scores(row_scores) scores = [] row_scores.split(',').each do |score| - scores.length < 18 && score == 'X' ? scores.push('X','0') : scores << score + scores.length < 18 && score == 'X' ? scores.push('X', '0') : scores << score end tenth_frame_scores = scores[18...scores.count] framed_scores = scores[0..17].each_slice(2).to_a From 74bec7395b024d28e4ad757d06e6fe5029f5f2b7 Mon Sep 17 00:00:00 2001 From: shoma Date: Wed, 26 Nov 2025 09:55:44 +0900 Subject: [PATCH 06/11] =?UTF-8?q?=E5=BF=85=E8=A6=81=E4=BB=A5=E4=B8=8A?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=95=B0=E3=81=AE=E3=82=B9=E3=82=B3=E3=83=BC?= =?UTF-8?q?=E3=83=97=E3=81=8C=E5=BA=83=E3=81=8B=E3=81=A3=E3=81=9F=E3=81=9F?= =?UTF-8?q?=E3=82=81=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 06.bowling_object/frame.rb | 16 ++++++---------- 06.bowling_object/game.rb | 19 +++++++++---------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/06.bowling_object/frame.rb b/06.bowling_object/frame.rb index f9fe26d13f..38600d618d 100644 --- a/06.bowling_object/frame.rb +++ b/06.bowling_object/frame.rb @@ -4,7 +4,6 @@ class Frame attr_reader :first_shot, :second_shot, :third_shot - attr_writer :referable_frames def initialize(first_score, second_score, third_score = nil) @first_shot = Shot.new(first_score) @@ -12,18 +11,16 @@ def initialize(first_score, second_score, third_score = nil) @third_shot = third_score.nil? ? nil : Shot.new(third_score) end - def total_score + def total_score(next_frame, after_the_next_frame) return [@first_shot.score, @second_shot.score, @third_shot.score].sum unless @third_shot.nil? total_score = [@first_shot.score, @second_shot.score].sum - total_score += strike_bounus if strike? - total_score += spare_bounus if spare? + total_score += strike_bounus(next_frame, after_the_next_frame) if strike? + total_score += spare_bounus(next_frame) if spare? total_score end - def strike_bounus - next_frame = @referable_frames[0] - after_the_next_frame = @referable_frames[1] + def strike_bounus(next_frame, after_the_next_frame) if next_frame.strike? # 9フレーム目の場合 return next_frame.first_shot.score + next_frame.second_shot.score if after_the_next_frame.nil? @@ -34,9 +31,8 @@ def strike_bounus end end - def spare_bounus - next_index = 0 - @referable_frames[next_index].first_shot.score + def spare_bounus(next_frame) + next_frame.first_shot.score end def spare? diff --git a/06.bowling_object/game.rb b/06.bowling_object/game.rb index 952a45dc76..6bd4f8511d 100644 --- a/06.bowling_object/game.rb +++ b/06.bowling_object/game.rb @@ -11,19 +11,18 @@ def initialize(row_scores) @frames = framed_scores.map do |score| Frame.new(*score) end - @frames.each_with_index do |frame, index| - # 9フレーム目であれば - if index.equal?(8) - frame.referable_frames = [@frames[index + 1]] - else - # 10フレーム目以外 - frame.referable_frames = [@frames[index + 1], @frames[index + 2]] unless index.equal?(9) - end - end end def total_score - @frames.sum(&:total_score) + total_score = 0 + @frames.each_with_index do |frame, index| + # 10フレーム目の場合nil + next_frame = !(index.equal?(9)) ? @frames[index + 1] : nil + # 9, 10フレーム目の場合nil + after_the_next_frame = !(index.equal?(8) || index.equal?(9)) ? @frames[index + 2] :nil + total_score += frame.total_score(next_frame, after_the_next_frame) + end + total_score end private From 9285adac492e37d61d53b764aafb9905fd54adae Mon Sep 17 00:00:00 2001 From: shoma Date: Wed, 26 Nov 2025 10:01:21 +0900 Subject: [PATCH 07/11] =?UTF-8?q?=E4=B8=80=E6=8A=95=E7=9B=AE=E3=81=A8?= =?UTF-8?q?=E4=BA=8C=E6=8A=95=E7=9B=AE=E3=81=AE=E3=82=B9=E3=82=B3=E3=82=A2?= =?UTF-8?q?=E3=82=92=E5=90=88=E7=AE=97=E3=81=99=E3=82=8B=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=81=8C=E8=A4=87=E6=95=B0=E5=80=8B=E6=89=80=E3=81=A7=E9=87=8D?= =?UTF-8?q?=E8=A4=87=E3=81=97=E3=81=A6=E3=81=84=E3=81=9F=E3=81=AE=E3=81=A7?= =?UTF-8?q?=E5=85=B1=E9=80=9A=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 06.bowling_object/frame.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/06.bowling_object/frame.rb b/06.bowling_object/frame.rb index 38600d618d..374485eda1 100644 --- a/06.bowling_object/frame.rb +++ b/06.bowling_object/frame.rb @@ -14,20 +14,24 @@ def initialize(first_score, second_score, third_score = nil) def total_score(next_frame, after_the_next_frame) return [@first_shot.score, @second_shot.score, @third_shot.score].sum unless @third_shot.nil? - total_score = [@first_shot.score, @second_shot.score].sum + total_score = total_score_first_and_second total_score += strike_bounus(next_frame, after_the_next_frame) if strike? total_score += spare_bounus(next_frame) if spare? total_score end + def total_score_first_and_second + [@first_shot, @second_shot].map(&:score).sum + end + def strike_bounus(next_frame, after_the_next_frame) if next_frame.strike? # 9フレーム目の場合 - return next_frame.first_shot.score + next_frame.second_shot.score if after_the_next_frame.nil? + return next_frame.total_score_first_and_second if after_the_next_frame.nil? next_frame.first_shot.score + after_the_next_frame.first_shot.score else - next_frame.first_shot.score + next_frame.second_shot.score + next_frame.total_score_first_and_second end end From f659eef665a9c64759c8a557532301fd6adeb757 Mon Sep 17 00:00:00 2001 From: shoma Date: Wed, 26 Nov 2025 10:08:50 +0900 Subject: [PATCH 08/11] =?UTF-8?q?=E8=A8=98=E8=BF=B0=E3=81=AE=E9=87=8D?= =?UTF-8?q?=E8=A4=87=E3=81=8C=E3=81=82=E3=81=A3=E3=81=9F=E3=81=9F=E3=82=81?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 06.bowling_object/frame.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/06.bowling_object/frame.rb b/06.bowling_object/frame.rb index 374485eda1..e5b628cdb5 100644 --- a/06.bowling_object/frame.rb +++ b/06.bowling_object/frame.rb @@ -12,7 +12,7 @@ def initialize(first_score, second_score, third_score = nil) end def total_score(next_frame, after_the_next_frame) - return [@first_shot.score, @second_shot.score, @third_shot.score].sum unless @third_shot.nil? + return [@first_shot, @second_shot, @third_shot].map(&:score).sum unless @third_shot.nil? total_score = total_score_first_and_second total_score += strike_bounus(next_frame, after_the_next_frame) if strike? @@ -29,7 +29,7 @@ def strike_bounus(next_frame, after_the_next_frame) # 9フレーム目の場合 return next_frame.total_score_first_and_second if after_the_next_frame.nil? - next_frame.first_shot.score + after_the_next_frame.first_shot.score + [next_frame.first_shot, after_the_next_frame.first_shot].map(&:score).sum else next_frame.total_score_first_and_second end From 59b13507d5e6a05e29a3dd38e7776206d305da97 Mon Sep 17 00:00:00 2001 From: shoma Date: Wed, 26 Nov 2025 10:36:56 +0900 Subject: [PATCH 09/11] =?UTF-8?q?=E5=85=B1=E7=94=A8=E3=81=AE=E6=95=B0?= =?UTF-8?q?=E5=80=A4=E3=82=92=E5=AE=9A=E6=95=B0=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 06.bowling_object/game.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/06.bowling_object/game.rb b/06.bowling_object/game.rb index 6bd4f8511d..2c1f3893d1 100644 --- a/06.bowling_object/game.rb +++ b/06.bowling_object/game.rb @@ -3,6 +3,7 @@ require_relative 'frame' class Game + ONE_TO_NICE_FRAMES_SHOTS_COUNT = 2 * 9 def initialize(row_scores) framed_scores = parse_scores(row_scores) # Frameクラス内のfirst_shot, second_shotとは命名の法則が異なっており統一感は無いが、 @@ -30,10 +31,10 @@ def total_score def parse_scores(row_scores) scores = [] row_scores.split(',').each do |score| - scores.length < 18 && score == 'X' ? scores.push('X', '0') : scores << score + scores.length < ONE_TO_NICE_FRAMES_SHOTS_COUNT && score == 'X' ? scores.push('X', '0') : scores << score end - tenth_frame_scores = scores[18...scores.count] - framed_scores = scores[0..17].each_slice(2).to_a + tenth_frame_scores = scores[ONE_TO_NICE_FRAMES_SHOTS_COUNT...scores.count] + framed_scores = scores.take(ONE_TO_NICE_FRAMES_SHOTS_COUNT).each_slice(2).to_a framed_scores << tenth_frame_scores end end From ef49cc1bfaaad06849f5507fa878db3018316c0a Mon Sep 17 00:00:00 2001 From: shoma Date: Wed, 26 Nov 2025 10:40:08 +0900 Subject: [PATCH 10/11] =?UTF-8?q?=E5=86=97=E9=95=B7=E3=81=AA=E8=A8=98?= =?UTF-8?q?=E8=BF=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 06.bowling_object/game.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/06.bowling_object/game.rb b/06.bowling_object/game.rb index 2c1f3893d1..c5c3cd2239 100644 --- a/06.bowling_object/game.rb +++ b/06.bowling_object/game.rb @@ -18,9 +18,9 @@ def total_score total_score = 0 @frames.each_with_index do |frame, index| # 10フレーム目の場合nil - next_frame = !(index.equal?(9)) ? @frames[index + 1] : nil + next_frame = !index.equal?(9) ? @frames[index + 1] : nil # 9, 10フレーム目の場合nil - after_the_next_frame = !(index.equal?(8) || index.equal?(9)) ? @frames[index + 2] :nil + after_the_next_frame = !(index.equal?(8) || index.equal?(9)) ? @frames[index + 2] : nil total_score += frame.total_score(next_frame, after_the_next_frame) end total_score From 8603fb803c32c25c77d95557dfcb7a2e39607dab Mon Sep 17 00:00:00 2001 From: shoma Date: Thu, 27 Nov 2025 09:24:34 +0900 Subject: [PATCH 11/11] =?UTF-8?q?=E5=BF=85=E8=A6=81=E3=81=AE=E3=81=AA?= =?UTF-8?q?=E3=81=84=E6=9D=A1=E4=BB=B6=E5=88=86=E5=B2=90=E3=81=A7=E3=81=82?= =?UTF-8?q?=E3=81=A3=E3=81=9F=E3=81=9F=E3=82=81=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 06.bowling_object/game.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/06.bowling_object/game.rb b/06.bowling_object/game.rb index c5c3cd2239..f4f5c9c942 100644 --- a/06.bowling_object/game.rb +++ b/06.bowling_object/game.rb @@ -17,10 +17,7 @@ def initialize(row_scores) def total_score total_score = 0 @frames.each_with_index do |frame, index| - # 10フレーム目の場合nil - next_frame = !index.equal?(9) ? @frames[index + 1] : nil - # 9, 10フレーム目の場合nil - after_the_next_frame = !(index.equal?(8) || index.equal?(9)) ? @frames[index + 2] : nil + next_frame, after_the_next_frame = @frames[index + 1, 2] total_score += frame.total_score(next_frame, after_the_next_frame) end total_score