diff --git a/bowling.rb b/bowling.rb new file mode 100755 index 0000000..f88a851 --- /dev/null +++ b/bowling.rb @@ -0,0 +1,39 @@ +#!/usr/bin/ruby + +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 + +frames = [] +shots.each_slice(2) do |s| + frames << s +end + +point = 0 +spare = false +strike1 = false +strike2 = false + +frames.each do |frame| + if frame[0] == 10 + point += 30 + elsif frame.sum == 10 + point += frame[0] + 10 + else + point += frame.sum + end +end +puts point + + +# 上記のコードを以下の旧式ルールに適合させる。 +# 10フレーム目だけ3投ある場合がある。 +# スペアとストライクの場合は現在のフレームだけでは計算ができない。(次の投球、次の次の投球の情報が必要)