fjord/bowling.rb

40 lines
729 B
Ruby
Raw Normal View History

2024-03-10 22:39:11 +09:00
#!/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投ある場合がある。
# スペアとストライクの場合は現在のフレームだけでは計算ができない。(次の投球、次の次の投球の情報が必要)