diff --git a/README.md b/README.md index bb10e86..49d4b90 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ I'm also adding notes that may be useful if you're learning Ruby. Notes for solving: * [2015, complete](year_2015.md) * [2016, up to day 08](year_2016.md) -* [2023, up to day 03](year_2023.md) +* [2023, up to day 04](year_2023.md) # How to use Install dependencies with `bundle install`. If you are in a hurry, just install [RSpec](https://github.com/rspec/rspec-metagem) with `gem install rspec` and run `rspec` in the root directory. diff --git a/spec/year_2015/day_04_input b/spec/year_2023/day_04_input similarity index 100% rename from spec/year_2015/day_04_input rename to spec/year_2023/day_04_input diff --git a/spec/year_2015/day_04_sample_one b/spec/year_2023/day_04_sample_one similarity index 100% rename from spec/year_2015/day_04_sample_one rename to spec/year_2023/day_04_sample_one diff --git a/spec/year_2015/day_04_sample_two b/spec/year_2023/day_04_sample_two similarity index 100% rename from spec/year_2015/day_04_sample_two rename to spec/year_2023/day_04_sample_two diff --git a/spec/year_2015/day_04_spec.rb b/spec/year_2023/day_04_spec.rb similarity index 83% rename from spec/year_2015/day_04_spec.rb rename to spec/year_2023/day_04_spec.rb index 0af03d0..1987127 100644 --- a/spec/year_2015/day_04_spec.rb +++ b/spec/year_2023/day_04_spec.rb @@ -1,9 +1,9 @@ -require 'year_2015/day_04' +require 'year_2023/day_04' -describe Year2015::Day04 do +describe Year2023::Day04 do context 'when Part 1' do subject(:sample_one) do - described_class.new(File.read('spec/year_2015/day_04_sample_one'), true) + described_class.new(File.read('spec/year_2023/day_04_sample_one'), true) end it 'finds winning numbers' do @@ -25,7 +25,7 @@ context 'when Part 2' do subject(:sample_two) do - described_class.new(File.read('spec/year_2015/day_04_sample_one')) + described_class.new(File.read('spec/year_2023/day_04_sample_one')) end it 'distributes cards' do @@ -41,7 +41,7 @@ context 'when Results' do subject(:input_data) do - File.read('spec/year_2015/day_04_input') + File.read('spec/year_2023/day_04_input') end it 'correctly answers part 1' do diff --git a/year_2023.md b/year_2023.md index 2b8ec15..9ab406a 100644 --- a/year_2023.md +++ b/year_2023.md @@ -77,4 +77,24 @@ I'm clearly not good enough with spatial representations (something about off-by Maybe I'll revisit this one with a better solution. -Also, thanks to the kind people or [/r/adventofcode](https://www.reddit.com/r/adventofcode/comments/189q9wv/2023_day_3_another_sample_grid_to_use/) for the sample grids they provided, they were a great help in debugging the first part properly. \ No newline at end of file +Also, thanks to the kind people or [/r/adventofcode](https://www.reddit.com/r/adventofcode/comments/189q9wv/2023_day_3_another_sample_grid_to_use/) for the sample grids they provided, they were a great help in debugging the first part properly. + +## Day 04: Scratchcards + +``` +Year2015::Day04 + Part 1 + finds winning numbers + calculates points + gives a final result + Part 2 + distributes cards + gives a final result + Results + correctly answers part 1 + correctly answers part 2 +``` + +Part one is pretty easy. One useful method is the [`#&`](https://ruby-doc.org/core-3.0.1/Array.html#method-i-26) operator that takes two arrays and returns a new one with only the matching contents. The syntax is clearly inspired by [bit masking](https://en.wikipedia.org/wiki/Mask_(computing)), which is a subject you should look into if you've never heard of it. + +Part two is a bit more annoying and requires to do a two-pass, but nothing really improbable. diff --git a/year_2015/day_04.rb b/year_2023/day_04.rb similarity index 98% rename from year_2015/day_04.rb rename to year_2023/day_04.rb index 0add241..e8da477 100644 --- a/year_2015/day_04.rb +++ b/year_2023/day_04.rb @@ -1,4 +1,4 @@ -class Year2015 +class Year2023 class Day04 attr_reader :version, :lines