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/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 new file mode 100755 index 0000000000..c753970fcc --- /dev/null +++ b/03.bowling/bowling.rb @@ -0,0 +1,43 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +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).to_a + +point = frames.map.with_index do |frame, i| + if i <= 8 + if frame[0] == 10 && frames[i + 1][0] == 10 + 10 + 10 + frames[i + 2][0] + elsif frame[0] == 10 && 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 && frames[10][0] == 10 + 10 + 10 + frames[11].sum + elsif frame[0] == 10 && frames[10][0] != 10 + 10 + frames[10].sum + elsif frame.sum == 10 + 10 + frames[10][0] + else + frame.sum + end + else + 0 + end +end +puts point.sum