From 9ffb11a397e1b146a64481ed4cbb2d0e4343718e Mon Sep 17 00:00:00 2001 From: Matt McMahand Date: Mon, 16 Dec 2024 11:32:27 -0500 Subject: [PATCH 1/5] wip --- .github/shared/setup/action.yaml | 8 +++----- .github/workflows/2021-ruby.yaml | 29 +++++++++++++++-------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/.github/shared/setup/action.yaml b/.github/shared/setup/action.yaml index bc7ca11..0b121e7 100644 --- a/.github/shared/setup/action.yaml +++ b/.github/shared/setup/action.yaml @@ -1,11 +1,9 @@ -name: "setup ruby" -description: "setup ruby" - +name: setup ruby +description: setup ruby runs: - using: "composite" + using: composite steps: - name: Set up Ruby uses: ruby/setup-ruby@v1 with: bundler-cache: true - working-directory: ./2024/ruby diff --git a/.github/workflows/2021-ruby.yaml b/.github/workflows/2021-ruby.yaml index 9231707..9c441d1 100644 --- a/.github/workflows/2021-ruby.yaml +++ b/.github/workflows/2021-ruby.yaml @@ -12,20 +12,21 @@ defaults: working-directory: ./2021/ruby jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: debug + run: pwd + - name: Setup Ruby + uses: ./.github/shared/setup + - name: Run rubocop + run: bundle exec rubocop tests: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Determine ruby version - id: determine-ruby-version - run: | - VERSION=$(cat .ruby-version) - echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT" - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ steps.determine-ruby-version.outputs.VERSION }} - bundler-cache: true - working-directory: ./2021/ruby - - name: Run tests - run: bundle exec rspec + - uses: actions/checkout@v3 + - name: Setup Ruby + uses: ./.github/shared/setup + - name: Run tests + run: bundle exec rspec From 37d227b7756c7e90ceb573a729603773e7987ea7 Mon Sep 17 00:00:00 2001 From: Matt McMahand Date: Mon, 16 Dec 2024 11:34:18 -0500 Subject: [PATCH 2/5] wip --- 2021/ruby/.ruby-version | 2 +- 2021/ruby/Gemfile.lock | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/2021/ruby/.ruby-version b/2021/ruby/.ruby-version index d9c62ed..9c25013 100644 --- a/2021/ruby/.ruby-version +++ b/2021/ruby/.ruby-version @@ -1 +1 @@ -3.0.2 \ No newline at end of file +3.3.6 diff --git a/2021/ruby/Gemfile.lock b/2021/ruby/Gemfile.lock index 29ef029..52ba2ab 100644 --- a/2021/ruby/Gemfile.lock +++ b/2021/ruby/Gemfile.lock @@ -43,6 +43,7 @@ GEM unicode-display_width (1.8.0) PLATFORMS + arm64-darwin-24 x86_64-linux DEPENDENCIES @@ -52,7 +53,7 @@ DEPENDENCIES rubocop (~> 0.60) RUBY VERSION - ruby 3.0.2p107 + ruby 3.3.6p108 BUNDLED WITH 2.2.22 From 101f0b39ac0a8dec01f5781638c86bc66de6997e Mon Sep 17 00:00:00 2001 From: Matt McMahand Date: Mon, 16 Dec 2024 11:50:58 -0500 Subject: [PATCH 3/5] ok workflow --- .github/shared/setup/action.yaml | 5 +++++ .github/workflows/2021-ruby.yaml | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/.github/shared/setup/action.yaml b/.github/shared/setup/action.yaml index 0b121e7..fd348a2 100644 --- a/.github/shared/setup/action.yaml +++ b/.github/shared/setup/action.yaml @@ -1,5 +1,9 @@ name: setup ruby description: setup ruby +inputs: + working-directory: + description: directory to use + required: true runs: using: composite steps: @@ -7,3 +11,4 @@ runs: uses: ruby/setup-ruby@v1 with: bundler-cache: true + working-directory: ${{ inputs.working-directory }} diff --git a/.github/workflows/2021-ruby.yaml b/.github/workflows/2021-ruby.yaml index 9c441d1..526f05b 100644 --- a/.github/workflows/2021-ruby.yaml +++ b/.github/workflows/2021-ruby.yaml @@ -20,6 +20,8 @@ jobs: run: pwd - name: Setup Ruby uses: ./.github/shared/setup + with: + working-directory: ./2021/ruby - name: Run rubocop run: bundle exec rubocop tests: @@ -28,5 +30,7 @@ jobs: - uses: actions/checkout@v3 - name: Setup Ruby uses: ./.github/shared/setup + with: + working-directory: ./2021/ruby - name: Run tests run: bundle exec rspec From f5376b3211c062f094949de464f7116f104de456 Mon Sep 17 00:00:00 2001 From: Matt McMahand Date: Mon, 16 Dec 2024 12:04:49 -0500 Subject: [PATCH 4/5] rubocop --- 2021/ruby/.rubocop.yml | 11 +++++++- 2021/ruby/.rubocop_todo.yml | 19 +++++++++++++ 2021/ruby/Gemfile | 14 +++++----- 2021/ruby/Gemfile.lock | 46 ++++++++++++++++++++------------ 2021/ruby/lib/advent_02.rb | 18 ++++++------- 2021/ruby/lib/advent_03.rb | 12 ++++----- 2021/ruby/spec/advent_01_spec.rb | 12 ++++----- 2021/ruby/spec/advent_02_spec.rb | 30 ++++++++++----------- 2021/ruby/spec/advent_03_spec.rb | 28 +++++++------------ 9 files changed, 110 insertions(+), 80 deletions(-) create mode 100644 2021/ruby/.rubocop_todo.yml diff --git a/2021/ruby/.rubocop.yml b/2021/ruby/.rubocop.yml index a44bea2..6accd83 100644 --- a/2021/ruby/.rubocop.yml +++ b/2021/ruby/.rubocop.yml @@ -1,3 +1,7 @@ +require: + - rubocop-rspec + - rubocop-rake + AllCops: Exclude: - bin/**/* @@ -8,7 +12,8 @@ Style/Documentation: Style/FrozenStringLiteralComment: Enabled: false Style/StringLiterals: - Enabled: false + Enabled: true + EnforcedStyle: double_quotes Style/TrailingCommaInHashLiteral: Enabled: false Style/NumericPredicate: @@ -16,5 +21,9 @@ Style/NumericPredicate: Metrics/BlockLength: Exclude: - spec/**/* +RSpec/ExampleLength: + Max: 20 +RSpec/MultipleExpectations: + Enabled: false inherit_from: .rubocop_todo.yml diff --git a/2021/ruby/.rubocop_todo.yml b/2021/ruby/.rubocop_todo.yml new file mode 100644 index 0000000..dfb999f --- /dev/null +++ b/2021/ruby/.rubocop_todo.yml @@ -0,0 +1,19 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2024-12-16 16:59:11 UTC using RuboCop version 1.69.2. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +RSpec/MultipleDescribes: + Exclude: + - 'spec/advent_02_spec.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings. +# URISchemes: http, https +Layout/LineLength: + Max: 122 diff --git a/2021/ruby/Gemfile b/2021/ruby/Gemfile index 4269dc0..1e39f42 100644 --- a/2021/ruby/Gemfile +++ b/2021/ruby/Gemfile @@ -1,10 +1,12 @@ # frozen_string_literal: true -source 'https://rubygems.org' +source "https://rubygems.org" -ruby File.open('.ruby-version', 'rb') { |f| f.read.chomp } +ruby File.open(".ruby-version", "rb") { |f| f.read.chomp } -gem 'awesome_print' -gem 'pry', '~> 0.12.0' -gem 'rspec', '~> 3.8.0' -gem 'rubocop', '~> 0.60' +gem "awesome_print" +gem "pry", "~> 0.12.0" +gem "rspec", "~> 3.8.0" +gem "rubocop", "~> 1.69.2" +gem "rubocop-rake", "~> 0.6.0" +gem "rubocop-rspec", "~> 3.2.0" diff --git a/2021/ruby/Gemfile.lock b/2021/ruby/Gemfile.lock index 52ba2ab..470614b 100644 --- a/2021/ruby/Gemfile.lock +++ b/2021/ruby/Gemfile.lock @@ -4,17 +4,20 @@ GEM ast (2.4.2) awesome_print (1.9.2) coderay (1.1.3) - diff-lcs (1.4.4) + diff-lcs (1.5.1) + json (2.9.0) + language_server-protocol (3.17.0.3) method_source (0.9.2) - parallel (1.21.0) - parser (3.0.3.1) + parallel (1.26.3) + parser (3.3.6.0) ast (~> 2.4.1) + racc pry (0.12.2) coderay (~> 1.1.0) method_source (~> 0.9.0) - rainbow (3.0.0) - regexp_parser (2.1.1) - rexml (3.2.5) + racc (1.8.1) + rainbow (3.1.1) + regexp_parser (2.9.3) rspec (3.8.0) rspec-core (~> 3.8.0) rspec-expectations (~> 3.8.0) @@ -28,19 +31,26 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.8.0) rspec-support (3.8.3) - rubocop (0.93.1) + rubocop (1.69.2) + json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 2.7.1.5) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8) - rexml - rubocop-ast (>= 0.6.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.36.2, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 2.0) - rubocop-ast (1.14.0) - parser (>= 3.0.1.1) - ruby-progressbar (1.11.0) - unicode-display_width (1.8.0) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.37.0) + parser (>= 3.3.1.0) + rubocop-rake (0.6.0) + rubocop (~> 1.0) + rubocop-rspec (3.2.0) + rubocop (~> 1.61) + ruby-progressbar (1.13.0) + unicode-display_width (3.1.2) + unicode-emoji (~> 4.0, >= 4.0.4) + unicode-emoji (4.0.4) PLATFORMS arm64-darwin-24 @@ -50,7 +60,9 @@ DEPENDENCIES awesome_print pry (~> 0.12.0) rspec (~> 3.8.0) - rubocop (~> 0.60) + rubocop (~> 1.69.2) + rubocop-rake (~> 0.6.0) + rubocop-rspec (~> 3.2.0) RUBY VERSION ruby 3.3.6p108 diff --git a/2021/ruby/lib/advent_02.rb b/2021/ruby/lib/advent_02.rb index dd55aa4..72f2a9e 100644 --- a/2021/ruby/lib/advent_02.rb +++ b/2021/ruby/lib/advent_02.rb @@ -1,4 +1,3 @@ - class DepthCalculator def initialize(data) @data = data @@ -8,18 +7,18 @@ def initialize(data) def process_action(action, amount) case action - when 'forward' + when "forward" @horizontal_position += amount - when 'down' + when "down" @depth += amount - when 'up' + when "up" @depth -= amount end end def process @data.each do |line| - action, amount = line.split(' ') + action, amount = line.split(" ") amount = amount.to_i process_action(action, amount) end @@ -30,7 +29,6 @@ def product end end - class AimCalculator def initialize(data) @data = data @@ -41,19 +39,19 @@ def initialize(data) def process_action(action, amount) case action - when 'forward' + when "forward" @horizontal_position += amount @depth += (@aim * amount) - when 'down' + when "down" @aim += amount - when 'up' + when "up" @aim -= amount end end def process @data.each do |line| - action, amount = line.split(' ') + action, amount = line.split(" ") amount = amount.to_i process_action(action, amount) end diff --git a/2021/ruby/lib/advent_03.rb b/2021/ruby/lib/advent_03.rb index e9c067e..f806a5f 100644 --- a/2021/ruby/lib/advent_03.rb +++ b/2021/ruby/lib/advent_03.rb @@ -31,27 +31,27 @@ def least_common_bit(data, index) def episolon_rate result = (0...@word_length).map { |index| least_common_bit(@data, index) } - result.join('').to_i(2) + result.join("").to_i(2) end def gamma_rate result = (0...@word_length).map { |index| most_common_bit(@data, index) } - result.join('').to_i(2) + result.join("").to_i(2) end def power_consumption episolon_rate * gamma_rate end - def determine_rating(data, use_most_common_bit = true, index = 0) - return 0 if data.length.zero? + def determine_rating(data, use_most_common_bit: true, index: 0) + return 0 if data.empty? return data[0].to_i(2) if data.length == 1 bit = use_most_common_bit ? most_common_bit(data, index) : least_common_bit(data, index) data.select! { |e| e[index] == bit.to_s } index += 1 - determine_rating(data, use_most_common_bit, index) + determine_rating(data, use_most_common_bit: use_most_common_bit, index: index) end def oxygen_generator_rating @@ -61,7 +61,7 @@ def oxygen_generator_rating def co2_scubber_rating to_process = @data.map(&:clone) - determine_rating(to_process, false) + determine_rating(to_process, use_most_common_bit: false) end def life_support_rating diff --git a/2021/ruby/spec/advent_01_spec.rb b/2021/ruby/spec/advent_01_spec.rb index f209307..6339313 100644 --- a/2021/ruby/spec/advent_01_spec.rb +++ b/2021/ruby/spec/advent_01_spec.rb @@ -1,17 +1,17 @@ -require 'spec_helper' -require 'advent_01' +require "spec_helper" +require "advent_01" -describe 'DepthCounter' do +describe "DepthCounter" do let(:puzzle_input) do - File.readlines('./spec/fixtures/advent-01.txt').map(&:to_i) + File.readlines("./spec/fixtures/advent-01.txt").map(&:to_i) end - it 'counts the number of increased measurements' do + it "counts the number of increased measurements" do count = DepthCounter.new(puzzle_input).total_increments expect(count).to be(1754) end - it 'counts using window measurement' do + it "counts using window measurement" do count = DepthCounter.new(puzzle_input).total_window_measurement_increments expect(count).to be(1789) diff --git a/2021/ruby/spec/advent_02_spec.rb b/2021/ruby/spec/advent_02_spec.rb index fd9339e..97c206a 100644 --- a/2021/ruby/spec/advent_02_spec.rb +++ b/2021/ruby/spec/advent_02_spec.rb @@ -1,12 +1,12 @@ -require 'spec_helper' -require 'advent_02' +require "spec_helper" +require "advent_02" -describe 'DepthCalculator' do +describe "DepthCalculator" do let(:puzzle_input) do - File.readlines('./spec/fixtures/advent-02.txt') + File.readlines("./spec/fixtures/advent-02.txt") end - it 'calculates the product' do + it "calculates the product" do dc = DepthCalculator.new(puzzle_input) dc.process @@ -14,19 +14,19 @@ end end -describe 'AimCalculator' do +describe "AimCalculator" do let(:puzzle_input) do - File.readlines('./spec/fixtures/advent-02.txt') + File.readlines("./spec/fixtures/advent-02.txt") end - it 'calculates the product from sample' do + it "calculates the product from sample" do sample_input = [ - 'forward 5', - 'down 5', - 'forward 8', - 'up 3', - 'down 8', - 'forward 2', + "forward 5", + "down 5", + "forward 8", + "up 3", + "down 8", + "forward 2" ] dc = AimCalculator.new(sample_input) @@ -35,7 +35,7 @@ expect(dc.product).to be(900) end - it 'calculates the product' do + it "calculates the product" do dc = AimCalculator.new(puzzle_input) dc.process diff --git a/2021/ruby/spec/advent_03_spec.rb b/2021/ruby/spec/advent_03_spec.rb index 4ceb551..f9a27db 100644 --- a/2021/ruby/spec/advent_03_spec.rb +++ b/2021/ruby/spec/advent_03_spec.rb @@ -1,25 +1,15 @@ -require 'spec_helper' -require 'advent_03' +require "spec_helper" +require "advent_03" -describe 'BinaryDiagnostic' do +describe "BinaryDiagnostic" do let(:puzzle_input) do - File.readlines('./spec/fixtures/advent-03.txt').map(&:chomp) + File.readlines("./spec/fixtures/advent-03.txt").map(&:chomp) end - it 'calculates the sample power consumption' do + it "calculates the sample power consumption" do sample_input = %w[ - 00100 - 11110 - 10110 - 10111 - 10101 - 01111 - 00111 - 11100 - 10000 - 11001 - 00010 - 01010 + 00100 11110 10110 10111 10101 01111 00111 11100 10000 11001 + 00010 01010 ] dc = BinaryDiagnostic.new(sample_input) @@ -34,13 +24,13 @@ expect(dc.life_support_rating).to be(230) end - it 'calculates the power consumption' do + it "calculates the power consumption" do dc = BinaryDiagnostic.new(puzzle_input) expect(dc.power_consumption).to be(388_256_4) end - it 'calculates life support rating' do + it "calculates life support rating" do dc = BinaryDiagnostic.new(puzzle_input) expect(dc.life_support_rating).to be(338_517_0) From 48ab8fd178943685d75801fc52e2ca37e0bb972b Mon Sep 17 00:00:00 2001 From: Matt McMahand Date: Mon, 16 Dec 2024 12:10:53 -0500 Subject: [PATCH 5/5] fix 2024 workflow --- .github/workflows/2024-ruby.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/2024-ruby.yaml b/.github/workflows/2024-ruby.yaml index 72ae51d..bd1a36c 100644 --- a/.github/workflows/2024-ruby.yaml +++ b/.github/workflows/2024-ruby.yaml @@ -17,6 +17,8 @@ jobs: - uses: actions/checkout@v3 - name: Setup Ruby uses: ./.github/shared/setup + with: + working-directory: ./2024/ruby - name: Run rubocop run: bundle exec rubocop tests: @@ -25,5 +27,7 @@ jobs: - uses: actions/checkout@v3 - name: Setup Ruby uses: ./.github/shared/setup + with: + working-directory: ./2024/ruby - name: Run tests run: bundle exec rspec pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy