From 481604712f37193ffbb0cdf59d1e9037aa1fde88 Mon Sep 17 00:00:00 2001 From: hiro23900 Date: Sat, 1 Aug 2026 18:33:49 +0900 Subject: [PATCH 1/5] first commit --- 03.bowling/bowling.rb | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100755 03.bowling/bowling.rb diff --git a/03.bowling/bowling.rb b/03.bowling/bowling.rb new file mode 100755 index 0000000000..6c2216dac2 --- /dev/null +++ b/03.bowling/bowling.rb @@ -0,0 +1,7 @@ +#!/usr/bin/env ruby + +# [[6, 3], [9, 0], [0, 3], [8, 2], [7, 3], [10, 0], [9, 1], [8, 0], [10, 0], [6, 4]] +# 1 2 3 4 5 6 7 8 9 10 + +scores = [[6, 3], [9, 0], [0, 3], [8, 2], [7, 3], [10, 0], [9, 1], [8, 0], [10, 0], [6, 4]] +p scores From 1c3a6d2a9bf5b2310d31f7a6f903b95c2c03c4f0 Mon Sep 17 00:00:00 2001 From: hiro23900 Date: Sun, 2 Aug 2026 10:40:23 +0900 Subject: [PATCH 2/5] Changed data structure.((frame_number), (frame)) --- 03.bowling/.rubocop.yml | 4 ++++ 03.bowling/Gemfile | 10 ++++++++++ 03.bowling/bowling.rb | 17 ++++++++++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 03.bowling/.rubocop.yml create mode 100644 03.bowling/Gemfile diff --git a/03.bowling/.rubocop.yml b/03.bowling/.rubocop.yml new file mode 100644 index 0000000000..6688e20de9 --- /dev/null +++ b/03.bowling/.rubocop.yml @@ -0,0 +1,4 @@ +# For plain Ruby scripts +inherit_gem: + rubocop-fjord: + - "config/rubocop.yml" diff --git a/03.bowling/Gemfile b/03.bowling/Gemfile new file mode 100644 index 0000000000..4a39293a91 --- /dev/null +++ b/03.bowling/Gemfile @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +source 'https://rubygems.org' + +# gem "rails" + +# For plain Ruby scripts +group :development do + gem 'rubocop-fjord', require: false +end diff --git a/03.bowling/bowling.rb b/03.bowling/bowling.rb index 6c2216dac2..5c805a8e8c 100755 --- a/03.bowling/bowling.rb +++ b/03.bowling/bowling.rb @@ -1,7 +1,18 @@ #!/usr/bin/env ruby # [[6, 3], [9, 0], [0, 3], [8, 2], [7, 3], [10, 0], [9, 1], [8, 0], [10, 0], [6, 4]] -# 1 2 3 4 5 6 7 8 9 10 +# [[6, 3], [9, 0], [0, 3], [8, 2], [7, 3], [10, 0], [9, 1], [8, 0], [10, 0], [10, 0], [6, 4]] +# 1 2 3 4 5 6 7 8 9 10 11 -scores = [[6, 3], [9, 0], [0, 3], [8, 2], [7, 3], [10, 0], [9, 1], [8, 0], [10, 0], [6, 4]] -p scores +frames = [[6, 3], [9, 0], [0, 3], [8, 2], [7, 3], [10, 0], [9, 1], [8, 0], [10, 0], [6, 4]] +frames_with_index = frames.map.with_index do |frame, i| + [i, frame] +end + +# (1) 単純に足す 22:44 +point = 0 +frames_with_index.each do |frame_with_index| + point += frame_with_index[1].sum +end +p frames_with_index +puts point From f4386497d6c52101df9ba050df7532b03d9a7deb Mon Sep 17 00:00:00 2001 From: hiro23900 Date: Mon, 3 Aug 2026 14:57:56 +0900 Subject: [PATCH 3/5] Undo new data structure. Continue programming. Completed. --- 03.bowling/Gemfile.lock | 69 +++++++++++++++++++++++++++++++++++++++++ 03.bowling/bowling.rb | 64 ++++++++++++++++++++++++++++++-------- 2 files changed, 120 insertions(+), 13 deletions(-) create mode 100644 03.bowling/Gemfile.lock diff --git a/03.bowling/Gemfile.lock b/03.bowling/Gemfile.lock new file mode 100644 index 0000000000..8f450850f1 --- /dev/null +++ b/03.bowling/Gemfile.lock @@ -0,0 +1,69 @@ +GEM + remote: https://rubygems.org/ + specs: + ast (2.4.3) + json (2.21.1) + language_server-protocol (3.17.0.6) + lint_roller (1.1.0) + parallel (2.1.0) + parser (3.3.12.0) + ast (~> 2.4.1) + racc + prism (1.9.0) + racc (1.8.1) + rainbow (3.1.1) + regexp_parser (2.12.0) + rubocop (1.88.2) + json (~> 2.3) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.1.0) + parallel (>= 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.49.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.50.0) + parser (>= 3.3.7.2) + prism (~> 1.7) + rubocop-fjord (0.4.0) + rubocop (>= 1.0) + rubocop-performance + rubocop-performance (1.26.1) + lint_roller (~> 1.1) + rubocop (>= 1.75.0, < 2.0) + rubocop-ast (>= 1.47.1, < 2.0) + ruby-progressbar (1.13.0) + unicode-display_width (3.2.0) + unicode-emoji (~> 4.1) + unicode-emoji (4.2.0) + +PLATFORMS + ruby + x86_64-linux + +DEPENDENCIES + rubocop-fjord + +CHECKSUMS + ast (2.4.3) sha256=954615157c1d6a382bc27d690d973195e79db7f55e9765ac7c481c60bdb4d383 + json (2.21.1) sha256=13a43df75d95641443f5702dff350f237164a9d811ff0f2c2800d4d980220583 + language_server-protocol (3.17.0.6) sha256=5ef2c0c138f8267e1bc631d3328347d354f96724b0af22f2c79516120443b7f0 + lint_roller (1.1.0) sha256=2c0c845b632a7d172cb849cc90c1bce937a28c5c8ccccb50dfd46a485003cc87 + parallel (2.1.0) sha256=b35258865c2e31134c5ecb708beaaf6772adf9d5efae28e93e99260877b09356 + parser (3.3.12.0) sha256=21a6d7f755d5a24dfbdc6e6b772e4e879a52e7631a88bc5a3a134606052c9828 + prism (1.9.0) sha256=7b530c6a9f92c24300014919c9dcbc055bf4cdf51ec30aed099b06cd6674ef85 + racc (1.8.1) sha256=4a7f6929691dbec8b5209a0b373bc2614882b55fc5d2e447a21aaa691303d62f + rainbow (3.1.1) sha256=039491aa3a89f42efa1d6dec2fc4e62ede96eb6acd95e52f1ad581182b79bc6a + regexp_parser (2.12.0) sha256=35a916a1d63190ab5c9009457136ae5f3c0c7512d60291d0d1378ba18ce08ebb + rubocop (1.88.2) sha256=8def251c90cd955feb4daa3edc0ab56893250c4ce90ef81e6c80c03f9a939bbf + rubocop-ast (1.50.0) sha256=b9ca88300da0803ee222ad20cdb30494c0a784eed06fdc35d254b06d662788db + rubocop-fjord (0.4.0) sha256=5937e4ebd97e315c609aa6ed867cde2dbeb4de2c0245d1a42b35e9c81e03ced3 + rubocop-performance (1.26.1) sha256=cd19b936ff196df85829d264b522fd4f98b6c89ad271fa52744a8c11b8f71834 + ruby-progressbar (1.13.0) sha256=80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33 + unicode-display_width (3.2.0) sha256=0cdd96b5681a5949cdbc2c55e7b420facae74c4aaf9a9815eee1087cb1853c42 + unicode-emoji (4.2.0) sha256=519e69150f75652e40bf736106cfbc8f0f73aa3fb6a65afe62fefa7f80b0f80f + +BUNDLED WITH + 4.0.10 diff --git a/03.bowling/bowling.rb b/03.bowling/bowling.rb index 5c805a8e8c..f5c547a42c 100755 --- a/03.bowling/bowling.rb +++ b/03.bowling/bowling.rb @@ -1,18 +1,56 @@ #!/usr/bin/env ruby -# [[6, 3], [9, 0], [0, 3], [8, 2], [7, 3], [10, 0], [9, 1], [8, 0], [10, 0], [6, 4]] -# [[6, 3], [9, 0], [0, 3], [8, 2], [7, 3], [10, 0], [9, 1], [8, 0], [10, 0], [10, 0], [6, 4]] -# 1 2 3 4 5 6 7 8 9 10 11 - -frames = [[6, 3], [9, 0], [0, 3], [8, 2], [7, 3], [10, 0], [9, 1], [8, 0], [10, 0], [6, 4]] -frames_with_index = frames.map.with_index do |frame, i| - [i, frame] +score = ARGV[0] +scores = score.split(',') +shots = [] +scores.each do |s| + if s == 'X' + shots << 10 + shots << 0 + else + shots << s.to_i + end end -# (1) 単純に足す 22:44 -point = 0 -frames_with_index.each do |frame_with_index| - point += frame_with_index[1].sum +frames = shots.each_slice(2).to_a +p frames + +# 0 1 2 3 4 5 6 7 8 9 10 11 +# frames = [[6, 3], [9, 0], [0, 3], [8, 2], [7, 3], [10, 0], [9, 1], [8, 0], [10, 0], [10, 0], [10, 0], [10, 0]] +# frames = [[6, 3], [9, 0], [0, 3], [8, 2], [7, 3], [10, 0], [9, 1], [8, 0], [10, 0], [10, 0], [5, 3]] +# 0 1 2 3 4 5 6 7 8 9 10 11 +# frames_with_index = frames.map.with_index do |frame, i| +# [i, frame] +# end +# p frames_with_index +# [[0, [6, 3]], [1, [9, 0]], [2, [0, 3]], [3, [8, 2]], [4, [7, 3]], [5, [10, 0]], [6, [9, 1]], [7, [8, 0]], +# [8, [10, 0]], [9, [10, 0]], [10, [10, 0]], [11, [10, 0]]] + +# binding.irb +point = frames.map.with_index do |frame, i| + if i <= 8 + if frame[0] == 10 and frames[i + 1][0] == 10 + 10 + 10 + frames[i + 2][0] + elsif frame[0] == 10 and 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 and frames[10][0] == 10 + 10 + 10 + frames[11].sum + elsif frame[0] == 10 and frames[10][0] != 10 + 10 + frames[10].sum + elsif frame.sum == 10 + 10 + frames[10][0] + else + frame.sum + end + else + 0 + end end -p frames_with_index -puts point +p point +puts point.sum From c21171d110f93d2d595b05c45126d470bcd5550d Mon Sep 17 00:00:00 2001 From: hiro23900 Date: Mon, 3 Aug 2026 15:05:37 +0900 Subject: [PATCH 4/5] Delete comment. --- 03.bowling/bowling.rb | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/03.bowling/bowling.rb b/03.bowling/bowling.rb index f5c547a42c..e44a029b49 100755 --- a/03.bowling/bowling.rb +++ b/03.bowling/bowling.rb @@ -13,20 +13,7 @@ end frames = shots.each_slice(2).to_a -p frames -# 0 1 2 3 4 5 6 7 8 9 10 11 -# frames = [[6, 3], [9, 0], [0, 3], [8, 2], [7, 3], [10, 0], [9, 1], [8, 0], [10, 0], [10, 0], [10, 0], [10, 0]] -# frames = [[6, 3], [9, 0], [0, 3], [8, 2], [7, 3], [10, 0], [9, 1], [8, 0], [10, 0], [10, 0], [5, 3]] -# 0 1 2 3 4 5 6 7 8 9 10 11 -# frames_with_index = frames.map.with_index do |frame, i| -# [i, frame] -# end -# p frames_with_index -# [[0, [6, 3]], [1, [9, 0]], [2, [0, 3]], [3, [8, 2]], [4, [7, 3]], [5, [10, 0]], [6, [9, 1]], [7, [8, 0]], -# [8, [10, 0]], [9, [10, 0]], [10, [10, 0]], [11, [10, 0]]] - -# binding.irb point = frames.map.with_index do |frame, i| if i <= 8 if frame[0] == 10 and frames[i + 1][0] == 10 @@ -52,5 +39,4 @@ 0 end end -p point puts point.sum From 6b3cc62168fd6e1e9b62dc3b222bc51699e9dbf2 Mon Sep 17 00:00:00 2001 From: hiro23900 Date: Mon, 3 Aug 2026 16:55:32 +0900 Subject: [PATCH 5/5] Correct the points pointed out by rubocop --- 03.bowling/bowling.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/03.bowling/bowling.rb b/03.bowling/bowling.rb index e44a029b49..c753970fcc 100755 --- a/03.bowling/bowling.rb +++ b/03.bowling/bowling.rb @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true score = ARGV[0] scores = score.split(',') @@ -16,9 +17,9 @@ point = frames.map.with_index do |frame, i| if i <= 8 - if frame[0] == 10 and frames[i + 1][0] == 10 + if frame[0] == 10 && frames[i + 1][0] == 10 10 + 10 + frames[i + 2][0] - elsif frame[0] == 10 and frames[i + 1][0] != 10 + elsif frame[0] == 10 && frames[i + 1][0] != 10 10 + frames[i + 1].sum elsif frame.sum == 10 10 + frames[i + 1][0] @@ -26,9 +27,9 @@ frame.sum end elsif i == 9 - if frame[0] == 10 and frames[10][0] == 10 + if frame[0] == 10 && frames[10][0] == 10 10 + 10 + frames[11].sum - elsif frame[0] == 10 and frames[10][0] != 10 + elsif frame[0] == 10 && frames[10][0] != 10 10 + frames[10].sum elsif frame.sum == 10 10 + frames[10][0]