From 6f336afef14650eabde5a06afcb4e057315865de Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Mon, 13 May 2024 10:58:24 +0900 Subject: [PATCH 01/44] add Gemfile --- Gemfile | 9 +++++++++ Gemfile.lock | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 Gemfile create mode 100644 Gemfile.lock diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000000..b40889cc67 --- /dev/null +++ b/Gemfile @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +source "https://rubygems.org" # rubocop:disable Style/StringLiterals + +# gem "rails" + +group :development do + gem 'rubocop-fjord', require: false +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000000..8fb80dc032 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,45 @@ +GEM + remote: https://rubygems.org/ + specs: + ast (2.4.2) + json (2.7.2) + language_server-protocol (3.17.0.3) + parallel (1.24.0) + parser (3.3.1.0) + ast (~> 2.4.1) + racc + racc (1.7.3) + rainbow (3.1.1) + regexp_parser (2.9.0) + rexml (3.2.6) + rubocop (1.63.5) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.3) + parser (>= 3.3.1.0) + rubocop-fjord (0.3.0) + rubocop (>= 1.0) + rubocop-performance + rubocop-performance (1.21.0) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (1.13.0) + unicode-display_width (2.5.0) + +PLATFORMS + arm64-darwin-22 + ruby + +DEPENDENCIES + rubocop-fjord + +BUNDLED WITH + 2.5.9 From 6a933e03199dbc21b888c0cadcf79cf6a648c246 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Mon, 13 May 2024 11:01:10 +0900 Subject: [PATCH 02/44] =?UTF-8?q?=E3=82=B9=E3=82=B3=E3=82=A2=E3=82=92?= =?UTF-8?q?=E5=90=88=E8=A8=88=E3=81=99=E3=82=8B=E3=81=A0=E3=81=91=E3=81=AE?= =?UTF-8?q?=E3=83=97=E3=83=AD=E3=82=B0=E3=83=A9=E3=83=A0=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .rubocop.yml | 2 +- 03.bowling/bowling_score.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100755 03.bowling/bowling_score.rb diff --git a/.rubocop.yml b/.rubocop.yml index f029f2ddad..f3dc714805 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,3 @@ inherit_gem: rubocop-fjord: - - "config/rubocop.yml" + - "config/rubocop.yml" \ No newline at end of file diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb new file mode 100755 index 0000000000..61685ba7d1 --- /dev/null +++ b/03.bowling/bowling_score.rb @@ -0,0 +1,11 @@ +# !/usr/bin/env ruby # rubocop:disable Style/FrozenStringLiteralComment + +score_list = ARGV[0].split(',') + +total = 0 # 合計得点を入力する変数 +score_list.each do |score| + score = '10' if score == 'X' + total += score.to_i +end + +p total From 13755e2bf190711619144d79151a33a5957976c7 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Mon, 13 May 2024 15:26:05 +0900 Subject: [PATCH 03/44] =?UTF-8?q?=E3=82=B9=E3=83=88=E3=83=A9=E3=82=A4?= =?UTF-8?q?=E3=82=AF=E3=83=BB=E3=82=B9=E3=83=9A=E3=82=A2=E6=99=82=E3=81=AB?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E5=BE=97=E7=82=B9=E3=82=92=E8=A8=98=E9=8C=B2?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=B3=E3=83=BC=E3=83=89=E3=82=92=E4=BD=9C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 40 ++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 61685ba7d1..d9fd7c8763 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -1,11 +1,41 @@ -# !/usr/bin/env ruby # rubocop:disable Style/FrozenStringLiteralComment +#!/usr/bin/env ruby # rubocop:disable Style/FrozenStringLiteralComment score_list = ARGV[0].split(',') total = 0 # 合計得点を入力する変数 -score_list.each do |score| - score = '10' if score == 'X' - total += score.to_i +flame = [1, 1] # フレーム、何回目かを管理する変数 +pre_score = 0 # 同フレームの前回のスコアを記録する変数 +strike_spare_flag = 0 # 前フレームが通常、スペア、ストライクのいずれかを判定する変数 + +# 得点加算部分の実装 +score_list.each do |score_s| + add_score = 0 # ストライク・スペアの際の加算得点を記録する変数 + if score_s == 'X' # ストライクだった時の処理 + score = 10 # Xを10に置き換える + # 前回がストライクないしスペアであった際には得点を+10する + add_score = 10 if strike_spare_flag > 0 # rubocop:disable Style/NumericPredicate + total += add_score + score # 得点を加算 + flame[0] += 1 # フレームを更新 + strike_spare_flag = 2 + next + end + # 1.前フレームがスペアないしストライクかどうかを判定し、いずれかに該当する場合は得点を加算する + if strike_spare_flag > 0 # rubocop:disable Style/NumericPredicate + add_score = score_s.to_i + strike_spare_flag -= 1 + end + + # 3.投球数、フレーム数の更新 + if flame[1] == 1 + flame[1] = 2 + pre_score = score_s.to_i + else + strike_spare_flag = 1 if pre_score + score_s.to_i == 10 # スペアになるかを判定し、該当する場合はフラグを1にする + flame[0] += 1 + flame[1] = 1 + pre_score = 0 + end + total += add_score + score_s.to_i # 得点を加算 end -p total +puts total From 0dd22be1646d45f3af3e4a19f7f3aca9bf8bdbb4 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Mon, 13 May 2024 16:01:17 +0900 Subject: [PATCH 04/44] =?UTF-8?q?=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89?= =?UTF-8?q?=E3=83=A9=E3=82=A4=E3=83=B3=E4=B8=8A=E3=81=AE=E6=95=B0=E5=80=A4?= =?UTF-8?q?=E5=A4=89=E6=8F=9B=E3=81=A8=E5=BE=97=E7=82=B9=E5=8A=A0=E7=AE=97?= =?UTF-8?q?=E6=99=82=E3=81=AE=E6=8C=99=E5=8B=95=E3=82=92=E3=83=A1=E3=82=BD?= =?UTF-8?q?=E3=83=83=E3=83=89=E3=81=A8=E3=81=97=E3=81=A6=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 48 +++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index d9fd7c8763..b36a4d47e2 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -3,39 +3,57 @@ score_list = ARGV[0].split(',') total = 0 # 合計得点を入力する変数 -flame = [1, 1] # フレーム、何回目かを管理する変数 +add_score = 0 # ストライク・スペアの際の加算得点を記録する変数 +flame = [1, 1] # フレーム、何投目かを管理する変数 pre_score = 0 # 同フレームの前回のスコアを記録する変数 strike_spare_flag = 0 # 前フレームが通常、スペア、ストライクのいずれかを判定する変数 +# スコアをint型に変換する +def convert_str2int(score_s) + if score_s == 'X' + 10 # Xを10に置き換える + else + score_s.to_i + end +end + +# ストライク・スペアの時の加算得点を計算するプログラム +def cal_addscore(score, flag) + if flag > 0 # rubocop:disable Style/NumericPredicate + add_score = score # 得点を加算 + flag -= 1 # フラグの数を減らす + else + add_score = 0 + end + return add_score, flag # rubocop:disable Style/RedundantReturn +end + # 得点加算部分の実装 score_list.each do |score_s| - add_score = 0 # ストライク・スペアの際の加算得点を記録する変数 + score_i = convert_str2int(score_s) # str型の数値をint型に変換する if score_s == 'X' # ストライクだった時の処理 - score = 10 # Xを10に置き換える - # 前回がストライクないしスペアであった際には得点を+10する - add_score = 10 if strike_spare_flag > 0 # rubocop:disable Style/NumericPredicate - total += add_score + score # 得点を加算 + # 前回がストライク・スペアの確認をする + add_score, strike_spare_flag = cal_addscore(score_i, strike_spare_flag) + total += add_score + score_i flame[0] += 1 # フレームを更新 strike_spare_flag = 2 next end - # 1.前フレームがスペアないしストライクかどうかを判定し、いずれかに該当する場合は得点を加算する - if strike_spare_flag > 0 # rubocop:disable Style/NumericPredicate - add_score = score_s.to_i - strike_spare_flag -= 1 - end - # 3.投球数、フレーム数の更新 + # 前フレームがスペアないしストライクかどうかを判定し、いずれかに該当する場合は得点を加算する + add_score, strike_spare_flag = cal_addscore(score_i, strike_spare_flag) + + # 投球数、フレーム数の更新 if flame[1] == 1 flame[1] = 2 - pre_score = score_s.to_i + pre_score = score_i else - strike_spare_flag = 1 if pre_score + score_s.to_i == 10 # スペアになるかを判定し、該当する場合はフラグを1にする + strike_spare_flag = 1 if pre_score + score_i == 10 # スペアになるかを判定し、該当する場合はフラグを1にする flame[0] += 1 flame[1] = 1 pre_score = 0 end - total += add_score + score_s.to_i # 得点を加算 + total += add_score + score_i # 得点を加算 end puts total From 16af2b25811d14a8559b8b09a1aa23899589ef1a Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Mon, 13 May 2024 16:14:19 +0900 Subject: [PATCH 05/44] =?UTF-8?q?=2010=E3=83=95=E3=83=AC=E3=83=BC=E3=83=A0?= =?UTF-8?q?=E7=9B=AE=E3=81=AE=E5=87=A6=E7=90=86=E3=82=92=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index b36a4d47e2..102d82c47c 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -31,7 +31,16 @@ def cal_addscore(score, flag) # 得点加算部分の実装 score_list.each do |score_s| score_i = convert_str2int(score_s) # str型の数値をint型に変換する - if score_s == 'X' # ストライクだった時の処理 + + # 10フレーム目の処理を別で実装 + if flame[0] == 10 + add_score, strike_spare_flag = cal_addscore(score_i, strike_spare_flag) # 前フレームでの加算得点処理 + total += add_score + score_i # 得点を加算 + next + end + + # ストライクだった時の処理 + if score_s == 'X' # 前回がストライク・スペアの確認をする add_score, strike_spare_flag = cal_addscore(score_i, strike_spare_flag) total += add_score + score_i @@ -44,16 +53,18 @@ def cal_addscore(score, flag) add_score, strike_spare_flag = cal_addscore(score_i, strike_spare_flag) # 投球数、フレーム数の更新 - if flame[1] == 1 + if flame[1] == 1 # 1投目 flame[1] = 2 pre_score = score_i - else + else # 2投目 strike_spare_flag = 1 if pre_score + score_i == 10 # スペアになるかを判定し、該当する場合はフラグを1にする flame[0] += 1 flame[1] = 1 pre_score = 0 end - total += add_score + score_i # 得点を加算 + + # 得点を加算 + total += add_score + score_i end puts total From 873dfbcf20ac74acf05a49f4b5be1aa4c1509fd8 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Mon, 13 May 2024 16:37:22 +0900 Subject: [PATCH 06/44] =?UTF-8?q?=E5=8A=A0=E7=AE=97=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=82=92=E6=9C=80=E5=88=9D=E3=81=AB=E7=A7=BB=E5=8B=95=E3=81=95?= =?UTF-8?q?=E3=81=9B=E3=81=A6=E3=82=B3=E3=83=BC=E3=83=89=E3=82=92=E7=B0=A1?= =?UTF-8?q?=E6=BD=94=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 102d82c47c..49b21d8f4f 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -31,10 +31,11 @@ def cal_addscore(score, flag) # 得点加算部分の実装 score_list.each do |score_s| score_i = convert_str2int(score_s) # str型の数値をint型に変換する + # 前フレームがスペアないしストライクかどうかを判定し、いずれかに該当する場合は得点を加算する + add_score, strike_spare_flag = cal_addscore(score_i, strike_spare_flag) # 10フレーム目の処理を別で実装 if flame[0] == 10 - add_score, strike_spare_flag = cal_addscore(score_i, strike_spare_flag) # 前フレームでの加算得点処理 total += add_score + score_i # 得点を加算 next end @@ -42,16 +43,12 @@ def cal_addscore(score, flag) # ストライクだった時の処理 if score_s == 'X' # 前回がストライク・スペアの確認をする - add_score, strike_spare_flag = cal_addscore(score_i, strike_spare_flag) total += add_score + score_i flame[0] += 1 # フレームを更新 strike_spare_flag = 2 next end - # 前フレームがスペアないしストライクかどうかを判定し、いずれかに該当する場合は得点を加算する - add_score, strike_spare_flag = cal_addscore(score_i, strike_spare_flag) - # 投球数、フレーム数の更新 if flame[1] == 1 # 1投目 flame[1] = 2 From 9c9584e077819a910458e5d9fc381e15e4817ef6 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Mon, 13 May 2024 16:49:27 +0900 Subject: [PATCH 07/44] =?UTF-8?q?=E9=80=A3=E7=B6=9A=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=83=A9=E3=82=A4=E3=82=AF=E3=81=AE=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 49b21d8f4f..8e4c9ffb6b 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -6,6 +6,8 @@ add_score = 0 # ストライク・スペアの際の加算得点を記録する変数 flame = [1, 1] # フレーム、何投目かを管理する変数 pre_score = 0 # 同フレームの前回のスコアを記録する変数 +pre_strike = false # 前フレームがストライクかの判定を行う +running_strike = false # 過去2フレームがどちらもストライクかを判定する変数 strike_spare_flag = 0 # 前フレームが通常、スペア、ストライクのいずれかを判定する変数 # スコアをint型に変換する @@ -18,21 +20,22 @@ def convert_str2int(score_s) end # ストライク・スペアの時の加算得点を計算するプログラム -def cal_addscore(score, flag) +def cal_addscore(score, flag, running_strike) if flag > 0 # rubocop:disable Style/NumericPredicate add_score = score # 得点を加算 flag -= 1 # フラグの数を減らす + add_score += score if running_strike == true else add_score = 0 end - return add_score, flag # rubocop:disable Style/RedundantReturn + return add_score, flag, false # rubocop:disable Style/RedundantReturn end # 得点加算部分の実装 score_list.each do |score_s| score_i = convert_str2int(score_s) # str型の数値をint型に変換する # 前フレームがスペアないしストライクかどうかを判定し、いずれかに該当する場合は得点を加算する - add_score, strike_spare_flag = cal_addscore(score_i, strike_spare_flag) + add_score, strike_spare_flag, running_strike = cal_addscore(score_i, strike_spare_flag, running_strike) # 10フレーム目の処理を別で実装 if flame[0] == 10 @@ -46,7 +49,11 @@ def cal_addscore(score, flag) total += add_score + score_i flame[0] += 1 # フレームを更新 strike_spare_flag = 2 + running_strike = true if pre_strike == true + pre_strike = true next + else + pre_strike = false end # 投球数、フレーム数の更新 From c90af8224c800d3f520e260f1042522489f8934a Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Mon, 13 May 2024 16:56:49 +0900 Subject: [PATCH 08/44] =?UTF-8?q?=E5=90=88=E8=A8=88=E5=BE=97=E7=82=B9?= =?UTF-8?q?=E5=8A=A0=E7=AE=97=E5=87=A6=E7=90=86=E3=82=92=E4=B8=80=E3=81=A4?= =?UTF-8?q?=E3=81=AB=E7=B5=B1=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 8e4c9ffb6b..cf1ed64212 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -32,7 +32,7 @@ def cal_addscore(score, flag, running_strike) end # 得点加算部分の実装 -score_list.each do |score_s| +score_list.each do |score_s| # rubocop:disable Metrics/BlockLength score_i = convert_str2int(score_s) # str型の数値をint型に変換する # 前フレームがスペアないしストライクかどうかを判定し、いずれかに該当する場合は得点を加算する add_score, strike_spare_flag, running_strike = cal_addscore(score_i, strike_spare_flag, running_strike) From d01afb76869abb4d595e9805dfe2a6ae688acafa Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Mon, 13 May 2024 16:59:57 +0900 Subject: [PATCH 09/44] =?UTF-8?q?if=E6=96=87=E5=87=A6=E7=90=86=E3=82=921?= =?UTF-8?q?=E8=A1=8C=E3=81=AB=E5=9C=A7=E7=B8=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index cf1ed64212..0124957735 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -32,21 +32,19 @@ def cal_addscore(score, flag, running_strike) end # 得点加算部分の実装 -score_list.each do |score_s| # rubocop:disable Metrics/BlockLength +score_list.each do |score_s| score_i = convert_str2int(score_s) # str型の数値をint型に変換する # 前フレームがスペアないしストライクかどうかを判定し、いずれかに該当する場合は得点を加算する add_score, strike_spare_flag, running_strike = cal_addscore(score_i, strike_spare_flag, running_strike) + # 得点を合計得点に加算 + total += add_score + score_i + # 10フレーム目の処理を別で実装 - if flame[0] == 10 - total += add_score + score_i # 得点を加算 - next - end + next if flame[0] == 10 # ストライクだった時の処理 if score_s == 'X' - # 前回がストライク・スペアの確認をする - total += add_score + score_i flame[0] += 1 # フレームを更新 strike_spare_flag = 2 running_strike = true if pre_strike == true @@ -66,9 +64,6 @@ def cal_addscore(score, flag, running_strike) flame[1] = 1 pre_score = 0 end - - # 得点を加算 - total += add_score + score_i end puts total From d2966068ecd7fbf9e82b8523bdbfc5bfecea09ab Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Mon, 20 May 2024 15:15:55 +0900 Subject: [PATCH 10/44] =?UTF-8?q?Gemfile=E3=81=8B=E3=82=89=E4=B8=8D?= =?UTF-8?q?=E8=A6=81=E3=81=AA=E8=A8=98=E8=BF=B0=E3=82=92=E6=B6=88=E5=8E=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Gemfile b/Gemfile index b40889cc67..ca5fb3ba31 100644 --- a/Gemfile +++ b/Gemfile @@ -2,8 +2,6 @@ source "https://rubygems.org" # rubocop:disable Style/StringLiterals -# gem "rails" - group :development do gem 'rubocop-fjord', require: false end From 4d6b63c2d0637d71be2e3e12cf67008508e43891 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Tue, 21 May 2024 11:06:30 +0900 Subject: [PATCH 11/44] =?UTF-8?q?=E5=A4=89=E6=95=B0=E5=90=8D=E5=AE=9A?= =?UTF-8?q?=E7=BE=A9=E3=81=AE=E9=9A=9B=E3=81=AE=E3=82=B3=E3=83=A1=E3=83=B3?= =?UTF-8?q?=E3=83=88=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 0124957735..afd3a003cb 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -1,14 +1,14 @@ #!/usr/bin/env ruby # rubocop:disable Style/FrozenStringLiteralComment score_list = ARGV[0].split(',') - -total = 0 # 合計得点を入力する変数 -add_score = 0 # ストライク・スペアの際の加算得点を記録する変数 -flame = [1, 1] # フレーム、何投目かを管理する変数 -pre_score = 0 # 同フレームの前回のスコアを記録する変数 -pre_strike = false # 前フレームがストライクかの判定を行う -running_strike = false # 過去2フレームがどちらもストライクかを判定する変数 -strike_spare_flag = 0 # 前フレームが通常、スペア、ストライクのいずれかを判定する変数 +p score_list +total = 0 +add_score = 0 +flame = [1, 1] +pre_score = 0 +pre_strike = false +running_strike = false +strike_spare_flag = 0 # スコアをint型に変換する def convert_str2int(score_s) From d642b10fc602514ff03030a5efc398c63c18d555 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Tue, 21 May 2024 15:30:46 +0900 Subject: [PATCH 12/44] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AAp=E3=83=A1?= =?UTF-8?q?=E3=82=BD=E3=83=83=E3=83=89=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index afd3a003cb..8edef1f181 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -1,7 +1,7 @@ #!/usr/bin/env ruby # rubocop:disable Style/FrozenStringLiteralComment score_list = ARGV[0].split(',') -p score_list + total = 0 add_score = 0 flame = [1, 1] From 5653e4f9e4f85f558b6b703740572f347c42d00f Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Tue, 21 May 2024 15:32:07 +0900 Subject: [PATCH 13/44] =?UTF-8?q?=E3=82=B9=E3=82=B3=E3=83=BC=E3=83=97?= =?UTF-8?q?=E5=A4=96=E3=81=AEadd=5Fscore=E3=81=AF=E5=BF=85=E8=A6=81?= =?UTF-8?q?=E3=81=AA=E3=81=84=E3=81=AE=E3=81=A7=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 8edef1f181..76c4502d9a 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -3,7 +3,6 @@ score_list = ARGV[0].split(',') total = 0 -add_score = 0 flame = [1, 1] pre_score = 0 pre_strike = false From 65ae1fb745527aac3dcca0a02e8943b95cbf3b15 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Tue, 21 May 2024 15:37:44 +0900 Subject: [PATCH 14/44] =?UTF-8?q?=E4=BA=88=E3=82=81=E3=83=9C=E3=82=A6?= =?UTF-8?q?=E3=83=AA=E3=83=B3=E3=82=B0=E3=81=AE=E3=82=B9=E3=82=B3=E3=82=A2?= =?UTF-8?q?=E3=83=AA=E3=82=B9=E3=83=88=E3=82=92int=E5=9E=8B=E3=81=AB?= =?UTF-8?q?=E5=A4=89=E6=8F=9B=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 76c4502d9a..e477b5f131 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -1,7 +1,5 @@ #!/usr/bin/env ruby # rubocop:disable Style/FrozenStringLiteralComment -score_list = ARGV[0].split(',') - total = 0 flame = [1, 1] pre_score = 0 @@ -9,14 +7,8 @@ running_strike = false strike_spare_flag = 0 -# スコアをint型に変換する -def convert_str2int(score_s) - if score_s == 'X' - 10 # Xを10に置き換える - else - score_s.to_i - end -end +score_list = ARGV[0].split(',') +score_list.map { |score| score == 'X' ? 10 : score.to_i } # ストライク・スペアの時の加算得点を計算するプログラム def cal_addscore(score, flag, running_strike) From e73488491c2024489e9f262e552e7d0d86b2a40e Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Tue, 21 May 2024 15:43:42 +0900 Subject: [PATCH 15/44] =?UTF-8?q?score=5Flist=E3=82=92=E4=BA=88=E3=82=81in?= =?UTF-8?q?t=E3=81=AB=E5=A4=89=E6=8F=9B=E3=81=99=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F=E3=81=9F=E3=82=81=E3=80=81?= =?UTF-8?q?score=5Fi,=20score=5Fs=E3=81=AE=E8=A8=98=E8=BC=89=E3=82=92?= =?UTF-8?q?=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index e477b5f131..de9ed3d18f 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -23,19 +23,18 @@ def cal_addscore(score, flag, running_strike) end # 得点加算部分の実装 -score_list.each do |score_s| - score_i = convert_str2int(score_s) # str型の数値をint型に変換する +score_list.each_with_index do |score, ball_number| # 前フレームがスペアないしストライクかどうかを判定し、いずれかに該当する場合は得点を加算する - add_score, strike_spare_flag, running_strike = cal_addscore(score_i, strike_spare_flag, running_strike) + add_score, strike_spare_flag, running_strike = cal_addscore(score, strike_spare_flag, running_strike) # 得点を合計得点に加算 - total += add_score + score_i + total += add_score + score # 10フレーム目の処理を別で実装 next if flame[0] == 10 # ストライクだった時の処理 - if score_s == 'X' + if score == 'X' flame[0] += 1 # フレームを更新 strike_spare_flag = 2 running_strike = true if pre_strike == true From 42334491e9ed3b7af2d746ce587f01a4734c0d73 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Tue, 21 May 2024 15:46:36 +0900 Subject: [PATCH 16/44] =?UTF-8?q?=3D=3D=20true=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index de9ed3d18f..f8cb533c2e 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -15,11 +15,11 @@ def cal_addscore(score, flag, running_strike) if flag > 0 # rubocop:disable Style/NumericPredicate add_score = score # 得点を加算 flag -= 1 # フラグの数を減らす - add_score += score if running_strike == true + add_score += score if running_strike else add_score = 0 end - return add_score, flag, false # rubocop:disable Style/RedundantReturn + [add_score, flag, false] end # 得点加算部分の実装 From 408c0c00cd77be9c13a13ac5ad66e458ab4484f2 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Tue, 21 May 2024 15:48:57 +0900 Subject: [PATCH 17/44] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E3=82=B3?= =?UTF-8?q?=E3=83=A1=E3=83=B3=E3=83=88=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index f8cb533c2e..b146460070 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -30,7 +30,6 @@ def cal_addscore(score, flag, running_strike) # 得点を合計得点に加算 total += add_score + score - # 10フレーム目の処理を別で実装 next if flame[0] == 10 # ストライクだった時の処理 From f5c19daf251cce9632333c4402af7643805d0ceb Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Tue, 21 May 2024 16:05:54 +0900 Subject: [PATCH 18/44] =?UTF-8?q?int=E5=9E=8B=E3=81=AB=E5=A4=89=E6=8F=9B?= =?UTF-8?q?=E3=81=97=E3=81=9Fscore=5Flist=E3=82=92=E6=A0=BC=E7=B4=8D?= =?UTF-8?q?=E3=81=97=E3=81=A6=E3=81=AA=E3=81=8B=E3=81=A3=E3=81=9F=E3=81=AE?= =?UTF-8?q?=E3=81=A7=E3=80=81=E3=81=9D=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index b146460070..21de37ef7c 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -8,7 +8,7 @@ strike_spare_flag = 0 score_list = ARGV[0].split(',') -score_list.map { |score| score == 'X' ? 10 : score.to_i } +score_list = score_list.map { |score| score == 'X' ? 10 : score.to_i } # ストライク・スペアの時の加算得点を計算するプログラム def cal_addscore(score, flag, running_strike) From a8163008e5e5b067a4afc7653778adb99b9dd631 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Tue, 21 May 2024 16:06:26 +0900 Subject: [PATCH 19/44] =?UTF-8?q?=3D=3D=20true=E3=81=AE=E8=A8=98=E8=BF=B0?= =?UTF-8?q?=E3=82=92=E6=B6=88=E5=8E=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 21de37ef7c..5da41da54b 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -36,7 +36,7 @@ def cal_addscore(score, flag, running_strike) if score == 'X' flame[0] += 1 # フレームを更新 strike_spare_flag = 2 - running_strike = true if pre_strike == true + running_strike = true if pre_strike pre_strike = true next else From fc36983891f77ac398dcea07247f370467af1656 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Tue, 21 May 2024 16:21:02 +0900 Subject: [PATCH 20/44] =?UTF-8?q?=E5=A4=89=E6=95=B0pre=5Fscore=E3=82=92?= =?UTF-8?q?=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 5da41da54b..b16b2befdd 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -2,7 +2,6 @@ total = 0 flame = [1, 1] -pre_score = 0 pre_strike = false running_strike = false strike_spare_flag = 0 @@ -46,12 +45,10 @@ def cal_addscore(score, flag, running_strike) # 投球数、フレーム数の更新 if flame[1] == 1 # 1投目 flame[1] = 2 - pre_score = score_i else # 2投目 - strike_spare_flag = 1 if pre_score + score_i == 10 # スペアになるかを判定し、該当する場合はフラグを1にする + strike_spare_flag = 1 if score_list[ball_number - 1] + score == 10 # スペアになるかを判定し、該当する場合はフラグを1にする flame[0] += 1 flame[1] = 1 - pre_score = 0 end end From a36e850063f9566eb2370aafb93552901e00204f Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Tue, 21 May 2024 16:22:15 +0900 Subject: [PATCH 21/44] =?UTF-8?q?=E3=82=B9=E3=82=B3=E3=82=A2=E7=82=B9?= =?UTF-8?q?=E6=95=B0=E3=81=AE=E5=87=A6=E7=90=86=E6=96=B9=E6=B3=95=E3=82=92?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index b16b2befdd..78161d3d71 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -32,7 +32,7 @@ def cal_addscore(score, flag, running_strike) next if flame[0] == 10 # ストライクだった時の処理 - if score == 'X' + if score == 10 flame[0] += 1 # フレームを更新 strike_spare_flag = 2 running_strike = true if pre_strike From 817ea142542b0d8e1035c569d7bf8b710729d69f Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Tue, 21 May 2024 16:22:46 +0900 Subject: [PATCH 22/44] =?UTF-8?q?=E5=A4=89=E6=95=B0pre=5Fstrike=E3=82=92?= =?UTF-8?q?=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 78161d3d71..6ec4d4e09b 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -2,7 +2,6 @@ total = 0 flame = [1, 1] -pre_strike = false running_strike = false strike_spare_flag = 0 @@ -35,11 +34,8 @@ def cal_addscore(score, flag, running_strike) if score == 10 flame[0] += 1 # フレームを更新 strike_spare_flag = 2 - running_strike = true if pre_strike - pre_strike = true + running_strike = true if score_list[ball_number - 1] == 10 next - else - pre_strike = false end # 投球数、フレーム数の更新 From ac6c0000f24553509b9adce73547b448dfc3303c Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Tue, 21 May 2024 16:26:22 +0900 Subject: [PATCH 23/44] =?UTF-8?q?=E5=A4=89=E6=95=B0running=5Fstrike?= =?UTF-8?q?=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 6ec4d4e09b..ab8dafcadb 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -2,28 +2,27 @@ total = 0 flame = [1, 1] -running_strike = false strike_spare_flag = 0 score_list = ARGV[0].split(',') score_list = score_list.map { |score| score == 'X' ? 10 : score.to_i } # ストライク・スペアの時の加算得点を計算するプログラム -def cal_addscore(score, flag, running_strike) +def cal_addscore(score, flag, score_list, ball_number) if flag > 0 # rubocop:disable Style/NumericPredicate add_score = score # 得点を加算 flag -= 1 # フラグの数を減らす - add_score += score if running_strike + add_score += score if score_list[ball_number - 1] && score_list[ball_number - 2] else add_score = 0 end - [add_score, flag, false] + [add_score, flag] end # 得点加算部分の実装 score_list.each_with_index do |score, ball_number| # 前フレームがスペアないしストライクかどうかを判定し、いずれかに該当する場合は得点を加算する - add_score, strike_spare_flag, running_strike = cal_addscore(score, strike_spare_flag, running_strike) + add_score, strike_spare_flag, = cal_addscore(score, strike_spare_flag, score_list, ball_number) # 得点を合計得点に加算 total += add_score + score @@ -34,7 +33,6 @@ def cal_addscore(score, flag, running_strike) if score == 10 flame[0] += 1 # フレームを更新 strike_spare_flag = 2 - running_strike = true if score_list[ball_number - 1] == 10 next end From 1d51126ae77bad637ba9e7c1da7cbdcd2ec238f8 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Tue, 21 May 2024 16:41:08 +0900 Subject: [PATCH 24/44] =?UTF-8?q?=E3=83=95=E3=83=AC=E3=83=BC=E3=83=A0?= =?UTF-8?q?=E6=95=B0=E3=83=BB=E6=8A=95=E7=90=83=E6=95=B0=E3=81=AE=E5=87=A6?= =?UTF-8?q?=E7=90=86=E3=81=A8=E3=82=B9=E3=83=88=E3=83=A9=E3=82=A4=E3=82=AF?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=82=92=E7=B5=B1=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index ab8dafcadb..fa12d79962 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -27,22 +27,18 @@ def cal_addscore(score, flag, score_list, ball_number) # 得点を合計得点に加算 total += add_score + score - next if flame[0] == 10 - - # ストライクだった時の処理 - if score == 10 - flame[0] += 1 # フレームを更新 - strike_spare_flag = 2 - next - end - # 投球数、フレーム数の更新 - if flame[1] == 1 # 1投目 - flame[1] = 2 - else # 2投目 - strike_spare_flag = 1 if score_list[ball_number - 1] + score == 10 # スペアになるかを判定し、該当する場合はフラグを1にする - flame[0] += 1 - flame[1] = 1 + if flame[0] == 10 # 10フレーム目はそれ以上フレーム数が更新されないので、個別に投球数を進める + flame[1] += 1 + else + if score == 10 # ストライク処理 + flame[0] += 1 + elsif flame[1] == 1 + flame[1] = 2 + else + flame[0] += 1 + flame[1] = 1 + end end end From d5c09ff0ce2a69c383814775a3fb957c9ae47e46 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Tue, 21 May 2024 17:09:14 +0900 Subject: [PATCH 25/44] =?UTF-8?q?=E6=8A=95=E7=90=83=E6=95=B0=E3=83=BB?= =?UTF-8?q?=E3=83=95=E3=83=AC=E3=83=BC=E3=83=A0=E6=95=B0=E3=81=AE=E6=9B=B8?= =?UTF-8?q?=E3=81=8D=E6=96=B9=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index fa12d79962..66e9feba1b 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -30,15 +30,13 @@ def cal_addscore(score, flag, score_list, ball_number) # 投球数、フレーム数の更新 if flame[0] == 10 # 10フレーム目はそれ以上フレーム数が更新されないので、個別に投球数を進める flame[1] += 1 - else - if score == 10 # ストライク処理 - flame[0] += 1 - elsif flame[1] == 1 - flame[1] = 2 - else - flame[0] += 1 - flame[1] = 1 - end + elsif flame[1] == 1 && score == 10 + flame[0] += 1 # ストライク処理 + elsif flame[1] == 1 + flame[1] = 2 + else + flame[0] += 1 + flame[1] = 1 end end From b13bcc5e15f83406ea3c4cd91d4d1d7ab56b1c5f Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Tue, 21 May 2024 17:10:46 +0900 Subject: [PATCH 26/44] =?UTF-8?q?=E3=82=B9=E3=83=88=E3=83=A9=E3=82=A4?= =?UTF-8?q?=E3=82=AF=E3=83=BB=E3=82=B9=E3=83=9A=E3=82=A2=E6=99=82=E3=81=AE?= =?UTF-8?q?=E3=82=B9=E3=82=B3=E3=82=A2=E5=8A=A0=E7=AE=97=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=82=92=E5=BE=8C=E3=81=8B=E3=82=89=E5=AE=9F=E8=A1=8C=E3=81=97?= =?UTF-8?q?=E3=81=A6=E3=81=84=E3=81=9F=E3=82=82=E3=81=AE=E3=82=92=E3=80=81?= =?UTF-8?q?=E5=85=88=E3=81=AB=E5=AE=9F=E8=A1=8C=E3=81=99=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 66e9feba1b..994c65e907 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -2,27 +2,25 @@ total = 0 flame = [1, 1] -strike_spare_flag = 0 score_list = ARGV[0].split(',') score_list = score_list.map { |score| score == 'X' ? 10 : score.to_i } # ストライク・スペアの時の加算得点を計算するプログラム -def cal_addscore(score, flag, score_list, ball_number) - if flag > 0 # rubocop:disable Style/NumericPredicate - add_score = score # 得点を加算 - flag -= 1 # フラグの数を減らす - add_score += score if score_list[ball_number - 1] && score_list[ball_number - 2] - else - add_score = 0 - end - [add_score, flag] +def cal_addscore(flame, score, score_list, ball_number) + add_score = 0 + return 0 if flame[0] == 10 + + add_score += score_list[ball_number + 1] + score_list[ball_number + 2] if flame[1] == 1 && score == 10 # ストライク判定 + add_score += score_list[ball_number + 1] if flame[1] == 2 && score_list[ball_number - 1] + score == 10 # スペア判定 + + add_score end # 得点加算部分の実装 score_list.each_with_index do |score, ball_number| # 前フレームがスペアないしストライクかどうかを判定し、いずれかに該当する場合は得点を加算する - add_score, strike_spare_flag, = cal_addscore(score, strike_spare_flag, score_list, ball_number) + add_score = cal_addscore(flame, score, score_list, ball_number) # 得点を合計得点に加算 total += add_score + score From 74d5fc9ba7e811a8f17643e719ac2d02d3c1dbd5 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Tue, 21 May 2024 17:12:53 +0900 Subject: [PATCH 27/44] =?UTF-8?q?=E5=BF=85=E8=A6=81=E3=81=AA=E3=81=84?= =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88=E3=81=AE=E5=89=8A=E9=99=A4?= =?UTF-8?q?=E3=81=A8=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=E5=90=8D=E3=82=92?= =?UTF-8?q?=E3=82=8F=E3=81=8B=E3=82=8A=E3=82=84=E3=81=99=E3=81=8F=E3=81=AA?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 994c65e907..0d7d20fe82 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -7,7 +7,7 @@ score_list = score_list.map { |score| score == 'X' ? 10 : score.to_i } # ストライク・スペアの時の加算得点を計算するプログラム -def cal_addscore(flame, score, score_list, ball_number) +def calculate_add_score(flame, score, score_list, ball_number) add_score = 0 return 0 if flame[0] == 10 @@ -19,10 +19,8 @@ def cal_addscore(flame, score, score_list, ball_number) # 得点加算部分の実装 score_list.each_with_index do |score, ball_number| - # 前フレームがスペアないしストライクかどうかを判定し、いずれかに該当する場合は得点を加算する - add_score = cal_addscore(flame, score, score_list, ball_number) + add_score = calculate_add_score(flame, score, score_list, ball_number) - # 得点を合計得点に加算 total += add_score + score # 投球数、フレーム数の更新 From c7547e6058ce7bab7da9fe4c3ac82f250bf33096 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Tue, 21 May 2024 17:16:46 +0900 Subject: [PATCH 28/44] =?UTF-8?q?=E5=8A=A0=E7=AE=97=E5=BE=97=E7=82=B9?= =?UTF-8?q?=E3=81=8C=E3=81=AA=E3=81=84=E9=9A=9B=E3=81=AB0=E3=82=92?= =?UTF-8?q?=E8=BF=94=E3=81=97=E3=81=A6=E3=81=84=E3=81=9F=E3=81=AE=E3=82=92?= =?UTF-8?q?add=5Fscore(=E4=B8=AD=E8=BA=AB=E3=81=AF0)=E3=82=92=E8=BF=94?= =?UTF-8?q?=E3=81=99=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 0d7d20fe82..f1340f2229 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -9,7 +9,7 @@ # ストライク・スペアの時の加算得点を計算するプログラム def calculate_add_score(flame, score, score_list, ball_number) add_score = 0 - return 0 if flame[0] == 10 + return add_score if flame[0] == 10 add_score += score_list[ball_number + 1] + score_list[ball_number + 2] if flame[1] == 1 && score == 10 # ストライク判定 add_score += score_list[ball_number + 1] if flame[1] == 2 && score_list[ball_number - 1] + score == 10 # スペア判定 From 42204905fb514f9aa86367b85effe385581fc3da Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Thu, 23 May 2024 15:14:54 +0900 Subject: [PATCH 29/44] =?UTF-8?q?=E6=94=B9=E8=A1=8C=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .rubocop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index f3dc714805..f029f2ddad 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,3 @@ inherit_gem: rubocop-fjord: - - "config/rubocop.yml" \ No newline at end of file + - "config/rubocop.yml" From 8139ac4057184f7a6a2b0107d0d1574bd3d6ab27 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Thu, 23 May 2024 15:19:25 +0900 Subject: [PATCH 30/44] =?UTF-8?q?frozen=5Fstring=5Fliteral:=20true?= =?UTF-8?q?=E3=81=AE=E9=A0=85=E7=9B=AE=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index f1340f2229..fab391db27 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -1,4 +1,5 @@ -#!/usr/bin/env ruby # rubocop:disable Style/FrozenStringLiteralComment +#!/usr/bin/env ruby +# frozen_string_literal: true total = 0 flame = [1, 1] From a3d09f34fcaf9d3777f47d4059cef1f99bb33b36 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Thu, 23 May 2024 15:28:19 +0900 Subject: [PATCH 31/44] =?UTF-8?q?flame=20Array=E3=82=92frame=E3=81=A8throw?= =?UTF-8?q?=E3=81=AB=E5=88=86=E5=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index fab391db27..7fa081c46e 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -2,38 +2,39 @@ # frozen_string_literal: true total = 0 -flame = [1, 1] +frame = 1 +throw = 1 score_list = ARGV[0].split(',') score_list = score_list.map { |score| score == 'X' ? 10 : score.to_i } # ストライク・スペアの時の加算得点を計算するプログラム -def calculate_add_score(flame, score, score_list, ball_number) +def calculate_add_score(frame, throw, score, score_list, ball_number) add_score = 0 - return add_score if flame[0] == 10 + return add_score if frame == 10 - add_score += score_list[ball_number + 1] + score_list[ball_number + 2] if flame[1] == 1 && score == 10 # ストライク判定 - add_score += score_list[ball_number + 1] if flame[1] == 2 && score_list[ball_number - 1] + score == 10 # スペア判定 + add_score += score_list[ball_number + 1] + score_list[ball_number + 2] if throw == 1 && score == 10 # ストライク判定 + add_score += score_list[ball_number + 1] if throw == 2 && score_list[ball_number - 1] + score == 10 # スペア判定 add_score end # 得点加算部分の実装 score_list.each_with_index do |score, ball_number| - add_score = calculate_add_score(flame, score, score_list, ball_number) + add_score = calculate_add_score(frame, throw, score, score_list, ball_number) total += add_score + score # 投球数、フレーム数の更新 - if flame[0] == 10 # 10フレーム目はそれ以上フレーム数が更新されないので、個別に投球数を進める - flame[1] += 1 - elsif flame[1] == 1 && score == 10 - flame[0] += 1 # ストライク処理 - elsif flame[1] == 1 - flame[1] = 2 + if frame == 10 # 10フレーム目はそれ以上フレーム数が更新されないので、個別に投球数を進める + throw += 1 + elsif throw == 1 && score == 10 + frame += 1 # ストライク処理 + elsif throw == 1 + throw = 2 else - flame[0] += 1 - flame[1] = 1 + frame += 1 + throw = 1 end end From ea4ca310e6339ed480aaaf8f33a335aa41390788 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Thu, 23 May 2024 15:36:22 +0900 Subject: [PATCH 32/44] =?UTF-8?q?calculate=5Fadd=5Fscore=E3=81=AE=E5=A4=96?= =?UTF-8?q?=E9=83=A8=E3=81=A7=E3=83=95=E3=83=AC=E3=83=BC=E3=83=A0=E6=95=B0?= =?UTF-8?q?=E3=82=92=E8=A8=88=E7=AE=97=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 7fa081c46e..5a97615c98 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -9,10 +9,8 @@ score_list = score_list.map { |score| score == 'X' ? 10 : score.to_i } # ストライク・スペアの時の加算得点を計算するプログラム -def calculate_add_score(frame, throw, score, score_list, ball_number) +def calculate_add_score(throw, score, score_list, ball_number) add_score = 0 - return add_score if frame == 10 - add_score += score_list[ball_number + 1] + score_list[ball_number + 2] if throw == 1 && score == 10 # ストライク判定 add_score += score_list[ball_number + 1] if throw == 2 && score_list[ball_number - 1] + score == 10 # スペア判定 @@ -21,8 +19,11 @@ def calculate_add_score(frame, throw, score, score_list, ball_number) # 得点加算部分の実装 score_list.each_with_index do |score, ball_number| - add_score = calculate_add_score(frame, throw, score, score_list, ball_number) - + add_score = if frame == 10 + 0 + else + calculate_add_score(throw, score, score_list, ball_number) + end total += add_score + score # 投球数、フレーム数の更新 From b93e2a2eb37cc8b7628480c1a937b86631feaa88 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Thu, 23 May 2024 15:49:06 +0900 Subject: [PATCH 33/44] =?UTF-8?q?Enumerable#sum=E3=82=92=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 5a97615c98..8c86c4f5dc 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -18,13 +18,12 @@ def calculate_add_score(throw, score, score_list, ball_number) end # 得点加算部分の実装 -score_list.each_with_index do |score, ball_number| +total = score_list.each_with_index.sum do |score, ball_number| add_score = if frame == 10 0 else calculate_add_score(throw, score, score_list, ball_number) end - total += add_score + score # 投球数、フレーム数の更新 if frame == 10 # 10フレーム目はそれ以上フレーム数が更新されないので、個別に投球数を進める @@ -37,6 +36,8 @@ def calculate_add_score(throw, score, score_list, ball_number) frame += 1 throw = 1 end + + add_score + score end puts total From 45be9b51f52c8b695432d37c28886b2667356dbe Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Thu, 23 May 2024 16:18:06 +0900 Subject: [PATCH 34/44] =?UTF-8?q?calculate=5Fadd=5Fscore=E3=81=AB=E6=B8=A1?= =?UTF-8?q?=E3=81=99=E5=80=A4=E3=82=92=E8=A8=88=E7=AE=97=E3=81=AB=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E3=81=AA=E8=A6=81=E7=B4=A0=E3=81=AB=E7=B5=9E=E3=81=A3?= =?UTF-8?q?=E3=81=A6score=5Fgroup=E3=81=AB=E6=A0=BC=E7=B4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 8c86c4f5dc..f1ed41c908 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -1,28 +1,27 @@ #!/usr/bin/env ruby # frozen_string_literal: true -total = 0 frame = 1 throw = 1 score_list = ARGV[0].split(',') score_list = score_list.map { |score| score == 'X' ? 10 : score.to_i } -# ストライク・スペアの時の加算得点を計算するプログラム -def calculate_add_score(throw, score, score_list, ball_number) +# ストライク・スペアの時の加算得点を計算 +def calculate_add_score(throw, score_group) add_score = 0 - add_score += score_list[ball_number + 1] + score_list[ball_number + 2] if throw == 1 && score == 10 # ストライク判定 - add_score += score_list[ball_number + 1] if throw == 2 && score_list[ball_number - 1] + score == 10 # スペア判定 + add_score += score_group[1] + score_group[2] if throw == 1 && score_group[0] == 10 # ストライク判定 + add_score += score_group[2] if throw == 1 && score_group[0] + score_group[1] == 10 # スペア判定 add_score end -# 得点加算部分の実装 -total = score_list.each_with_index.sum do |score, ball_number| +total = score_list.each_with_index.sum do |score, index| + score_group = score_list[index, 3] add_score = if frame == 10 0 else - calculate_add_score(throw, score, score_list, ball_number) + calculate_add_score(throw, score_group) end # 投球数、フレーム数の更新 From 3693dd47d2e355f065f14a0e3c0eec4ad83e3a4b Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Mon, 27 May 2024 09:57:21 +0900 Subject: [PATCH 35/44] =?UTF-8?q?=E3=82=B9=E3=83=88=E3=83=A9=E3=82=A4?= =?UTF-8?q?=E3=82=AF=E3=83=BB=E3=82=B9=E3=83=9A=E3=82=A2=E6=99=82=E3=81=AE?= =?UTF-8?q?=E3=82=B9=E3=82=B3=E3=82=A2=E5=8A=A0=E7=AE=97=E5=BC=8F=E3=82=92?= =?UTF-8?q?=E7=9F=AD=E3=81=84=E8=A1=A8=E7=8F=BE=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index f1ed41c908..50f83c6108 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -10,8 +10,8 @@ # ストライク・スペアの時の加算得点を計算 def calculate_add_score(throw, score_group) add_score = 0 - add_score += score_group[1] + score_group[2] if throw == 1 && score_group[0] == 10 # ストライク判定 - add_score += score_group[2] if throw == 1 && score_group[0] + score_group[1] == 10 # スペア判定 + add_score += score_group[1..2] if throw == 1 && score_group[0] == 10 # ストライク判定 + add_score += score_group[2] if throw == 1 && score_group[0..1] == 10 # スペア判定 add_score end From 35bd1af12a7415f0d0f58d9021e47b8ac16184f3 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Mon, 27 May 2024 10:08:31 +0900 Subject: [PATCH 36/44] =?UTF-8?q?.sum=E3=81=AE=E3=81=A4=E3=81=91=E5=BF=98?= =?UTF-8?q?=E3=82=8C=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 50f83c6108..99d9bdfa40 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -10,8 +10,8 @@ # ストライク・スペアの時の加算得点を計算 def calculate_add_score(throw, score_group) add_score = 0 - add_score += score_group[1..2] if throw == 1 && score_group[0] == 10 # ストライク判定 - add_score += score_group[2] if throw == 1 && score_group[0..1] == 10 # スペア判定 + add_score += score_group[1..2].sum if throw == 1 && score_group[0] == 10 # ストライク判定 + add_score += score_group[2] if throw == 1 && score_group[0..1].sum == 10 # スペア判定 add_score end From 3b654fa0ba528a5675920ffb55f3312315b0c9bd Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Mon, 27 May 2024 10:17:51 +0900 Subject: [PATCH 37/44] =?UTF-8?q?10=E3=83=95=E3=83=AC=E3=83=BC=E3=83=A0?= =?UTF-8?q?=E7=9B=AE=E3=81=AE=E5=87=A6=E7=90=86=E3=82=92=E7=9F=AD=E7=B8=AE?= =?UTF-8?q?=E3=81=97=E3=80=81=E5=90=8C=E4=B8=80=E3=83=96=E3=83=AD=E3=83=83?= =?UTF-8?q?=E3=82=AF=E5=86=85=E3=81=A7frame=20=3D=3D=2010=E3=81=AE?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=82=92=E4=B8=80=E3=81=A4=E3=81=AB=E3=81=BE?= =?UTF-8?q?=E3=81=A8=E3=82=81=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 99d9bdfa40..2a7113d4b2 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -19,16 +19,14 @@ def calculate_add_score(throw, score_group) total = score_list.each_with_index.sum do |score, index| score_group = score_list[index, 3] add_score = if frame == 10 - 0 + next score else calculate_add_score(throw, score_group) end # 投球数、フレーム数の更新 - if frame == 10 # 10フレーム目はそれ以上フレーム数が更新されないので、個別に投球数を進める - throw += 1 - elsif throw == 1 && score == 10 - frame += 1 # ストライク処理 + if throw == 1 && score == 10 + frame += 1 elsif throw == 1 throw = 2 else From 38b5ad41840282063b60c6dd37b3b0c9db205a26 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Mon, 27 May 2024 11:34:12 +0900 Subject: [PATCH 38/44] =?UTF-8?q?=E3=83=95=E3=83=AC=E3=83=BC=E3=83=A0?= =?UTF-8?q?=E6=95=B0=E3=83=BB=E6=8A=95=E7=90=83=E6=95=B0=E3=81=AE=E5=87=A6?= =?UTF-8?q?=E7=90=86=E3=82=92=E7=B0=A1=E6=BD=94=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 2a7113d4b2..9790ba20a0 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -25,13 +25,11 @@ def calculate_add_score(throw, score_group) end # 投球数、フレーム数の更新 - if throw == 1 && score == 10 - frame += 1 - elsif throw == 1 - throw = 2 - else + if throw == 1 && score == 10 || throw == 2 frame += 1 throw = 1 + else + throw = 2 end add_score + score From 28401e2938463b3ee3ceb8001385f54ad4cfcba6 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Tue, 28 May 2024 10:57:22 +0900 Subject: [PATCH 39/44] =?UTF-8?q?=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89?= =?UTF-8?q?=E5=90=8D=E3=82=92calculate=5Fadd=5Fscore=E3=81=8B=E3=82=89upda?= =?UTF-8?q?te=5Fgame=5Fstate=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 9790ba20a0..c8d596e3f3 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -7,24 +7,26 @@ score_list = ARGV[0].split(',') score_list = score_list.map { |score| score == 'X' ? 10 : score.to_i } -# ストライク・スペアの時の加算得点を計算 -def calculate_add_score(throw, score_group) +def update_game_state(frame, throw, score_group) add_score = 0 - add_score += score_group[1..2].sum if throw == 1 && score_group[0] == 10 # ストライク判定 - add_score += score_group[2] if throw == 1 && score_group[0..1].sum == 10 # スペア判定 + if throw == 1 && score_group[0] == 10 # ストライク判定 + add_score += score_group[1..2].sum + end + if throw == 1 && score_group[0..1].sum == 10 # スペア判定 + add_score += score_group[2] + end add_score end total = score_list.each_with_index.sum do |score, index| score_group = score_list[index, 3] - add_score = if frame == 10 - next score - else - calculate_add_score(throw, score_group) - end + if frame == 10 + next score + else + add_score, frame, throw = update_game_state(frame, throw, score_group) + end - # 投球数、フレーム数の更新 if throw == 1 && score == 10 || throw == 2 frame += 1 throw = 1 From 68ca318d0f905700cb7e4c7958af2014ea59882a Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Tue, 28 May 2024 11:11:22 +0900 Subject: [PATCH 40/44] =?UTF-8?q?=E3=83=95=E3=83=AC=E3=83=BC=E3=83=A0?= =?UTF-8?q?=E6=95=B0=E3=83=BB=E6=8A=95=E7=90=83=E6=95=B0=E3=81=AE=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E3=82=92update=5Fgame=5Fstate=E5=86=85=E3=81=A7?= =?UTF-8?q?=E5=AE=9F=E8=A1=8C=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index c8d596e3f3..301d71ab4b 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -11,28 +11,24 @@ def update_game_state(frame, throw, score_group) add_score = 0 if throw == 1 && score_group[0] == 10 # ストライク判定 add_score += score_group[1..2].sum - end - if throw == 1 && score_group[0..1].sum == 10 # スペア判定 + frame += 1 + throw = 1 + elsif throw == 1 && score_group[0..1].sum == 10 # スペア判定 add_score += score_group[2] + throw = 2 + else + frame += 1 if throw == 2 + throw = (throw == 2 ? 1 : 2) end - add_score + [add_score, frame, throw] end total = score_list.each_with_index.sum do |score, index| - score_group = score_list[index, 3] - if frame == 10 - next score - else - add_score, frame, throw = update_game_state(frame, throw, score_group) - end + next score if frame == 10 - if throw == 1 && score == 10 || throw == 2 - frame += 1 - throw = 1 - else - throw = 2 - end + score_group = score_list[index, 3] + add_score, frame, throw = update_game_state(frame, throw, score_group) add_score + score end From 8a39b9b8e903cd65cdd4415f81b1feb326020e50 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Tue, 28 May 2024 11:21:03 +0900 Subject: [PATCH 41/44] =?UTF-8?q?=E3=82=B9=E3=83=88=E3=83=A9=E3=82=A4?= =?UTF-8?q?=E3=82=AF=E6=99=82=E3=81=AFthrow=3D1=E3=81=AA=E3=81=AE=E3=81=A7?= =?UTF-8?q?=E3=80=81=E3=82=B9=E3=83=88=E3=83=A9=E3=82=A4=E3=82=AF=E6=99=82?= =?UTF-8?q?=E3=81=ABthrow=E3=82=92=E6=9B=B4=E6=96=B0=E3=81=99=E3=82=8B?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=81=8C=E5=BF=85=E8=A6=81=E3=81=AA=E3=81=84?= =?UTF-8?q?=E3=81=9F=E3=82=81=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 301d71ab4b..690d27f2a9 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -12,7 +12,6 @@ def update_game_state(frame, throw, score_group) if throw == 1 && score_group[0] == 10 # ストライク判定 add_score += score_group[1..2].sum frame += 1 - throw = 1 elsif throw == 1 && score_group[0..1].sum == 10 # スペア判定 add_score += score_group[2] throw = 2 From 1c730789d151ab8d109f39b5e9aed734a075c46f Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Thu, 30 May 2024 12:19:52 +0900 Subject: [PATCH 42/44] =?UTF-8?q?update=5Fgame=5Fstate=E5=86=85=E3=81=AE?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=82=92=E5=91=BC=E3=81=B3=E5=87=BA=E3=81=97?= =?UTF-8?q?=E5=85=83=E3=81=AB=E6=88=BB=E3=81=97=E3=81=A6=E3=83=A1=E3=82=BD?= =?UTF-8?q?=E3=83=83=E3=83=89=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 690d27f2a9..4996264dec 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -7,7 +7,10 @@ score_list = ARGV[0].split(',') score_list = score_list.map { |score| score == 'X' ? 10 : score.to_i } -def update_game_state(frame, throw, score_group) +total = score_list.each_with_index.sum do |score, index| + next score if frame == 10 + + score_group = score_list[index, 3] add_score = 0 if throw == 1 && score_group[0] == 10 # ストライク判定 add_score += score_group[1..2].sum @@ -20,15 +23,6 @@ def update_game_state(frame, throw, score_group) throw = (throw == 2 ? 1 : 2) end - [add_score, frame, throw] -end - -total = score_list.each_with_index.sum do |score, index| - next score if frame == 10 - - score_group = score_list[index, 3] - add_score, frame, throw = update_game_state(frame, throw, score_group) - add_score + score end From 66e2630eb3fc3b6811584a7bbca29f418ce314a8 Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Thu, 30 May 2024 12:32:44 +0900 Subject: [PATCH 43/44] =?UTF-8?q?throw=3D=3D2=E3=81=AE=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=81=8C=E9=87=8D=E8=A4=87=E3=81=97=E3=81=A6=E3=81=84=E3=81=9F?= =?UTF-8?q?=E3=81=AE=E3=81=A7=E4=B8=80=E3=81=A4=E3=81=AB=E7=B5=B1=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 4996264dec..09701ef2dc 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -19,8 +19,12 @@ add_score += score_group[2] throw = 2 else - frame += 1 if throw == 2 - throw = (throw == 2 ? 1 : 2) + if throw == 2 + frame += 1 + throw = 1 + else + throw = 2 + end end add_score + score From 49a06568f844f67504d5738e1e1403247ba16fed Mon Sep 17 00:00:00 2001 From: "yuichi.imori" Date: Thu, 30 May 2024 12:54:27 +0900 Subject: [PATCH 44/44] =?UTF-8?q?=E3=82=B9=E3=83=88=E3=83=A9=E3=82=A4?= =?UTF-8?q?=E3=82=AF=E3=83=BB=E3=82=B9=E3=83=9A=E3=82=A2=E3=83=BB=E3=81=9D?= =?UTF-8?q?=E3=81=AE=E4=BB=96=E5=88=A4=E5=AE=9A=E3=81=AE=E6=9C=80=E9=81=A9?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.bowling/bowling_score.rb | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb index 09701ef2dc..0585e6d39c 100755 --- a/03.bowling/bowling_score.rb +++ b/03.bowling/bowling_score.rb @@ -11,20 +11,18 @@ next score if frame == 10 score_group = score_list[index, 3] - add_score = 0 - if throw == 1 && score_group[0] == 10 # ストライク判定 - add_score += score_group[1..2].sum - frame += 1 - elsif throw == 1 && score_group[0..1].sum == 10 # スペア判定 - add_score += score_group[2] - throw = 2 - else - if throw == 2 + if throw == 1 + if score_group[0] == 10 # ストライク判定 + add_score = score_group[1..2].sum frame += 1 - throw = 1 else + add_score = (score_group[0..1].sum == 10 ? score_group[2] : 0) # スペアかそうでないか判定 throw = 2 end + else + add_score = 0 + frame += 1 + throw = 1 end add_score + score