diff --git a/03.bowling/bowling_score.rb b/03.bowling/bowling_score.rb new file mode 100755 index 0000000000..0585e6d39c --- /dev/null +++ b/03.bowling/bowling_score.rb @@ -0,0 +1,31 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +frame = 1 +throw = 1 + +score_list = ARGV[0].split(',') +score_list = score_list.map { |score| score == 'X' ? 10 : score.to_i } + +total = score_list.each_with_index.sum do |score, index| + next score if frame == 10 + + score_group = score_list[index, 3] + if throw == 1 + if score_group[0] == 10 # ストライク判定 + add_score = score_group[1..2].sum + frame += 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 +end + +puts total diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000000..ca5fb3ba31 --- /dev/null +++ b/Gemfile @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +source "https://rubygems.org" # rubocop:disable Style/StringLiterals + +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