-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generators galore!
- Loading branch information
Showing
12 changed files
with
167 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--color | ||
--format documentation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.3.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
source 'https://rubygems.org' | ||
|
||
ruby '3.3.4' | ||
|
||
gem 'rspec' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
diff-lcs (1.5.1) | ||
rspec (3.13.0) | ||
rspec-core (~> 3.13.0) | ||
rspec-expectations (~> 3.13.0) | ||
rspec-mocks (~> 3.13.0) | ||
rspec-core (3.13.2) | ||
rspec-support (~> 3.13.0) | ||
rspec-expectations (3.13.3) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.13.0) | ||
rspec-mocks (3.13.2) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.13.0) | ||
rspec-support (3.13.1) | ||
|
||
PLATFORMS | ||
arm64-darwin-23 | ||
ruby | ||
|
||
DEPENDENCIES | ||
rspec | ||
|
||
RUBY VERSION | ||
ruby 3.3.4p94 | ||
|
||
BUNDLED WITH | ||
2.5.22 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require_relative '../lib/application' | ||
|
||
if ARGV.empty? | ||
puts "Usage: bin/aoc DAY" | ||
puts "Example: bin/aoc 1" | ||
exit 1 | ||
end | ||
|
||
day = ARGV[0].to_i | ||
AdventOfCode2024.run(day) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'fileutils' | ||
|
||
def create_day(day) | ||
day_str = day.to_s.rjust(2, '0') | ||
|
||
# Create directories if they don't exist | ||
FileUtils.mkdir_p('lib/solutions') | ||
FileUtils.mkdir_p('lib/input') | ||
FileUtils.mkdir_p('spec/solutions') | ||
FileUtils.mkdir_p('spec/input') | ||
|
||
# Copy solution template | ||
solution_template = File.read('templates/day.rb') | ||
File.write( | ||
"lib/solutions/day_#{day_str}.rb", | ||
solution_template % { day: day_str } | ||
) | ||
|
||
# Copy test template | ||
test_template = File.read('templates/day_spec.rb') | ||
File.write( | ||
"spec/solutions/day_#{day_str}_spec.rb", | ||
test_template % { day: day_str } | ||
) | ||
|
||
# Create empty input file | ||
FileUtils.touch("lib/input/day_#{day_str}.txt") | ||
FileUtils.touch("spec/input/day_#{day_str}_test.txt") | ||
|
||
puts "Created files for day #{day_str}:" | ||
puts " - lib/solutions/day_#{day_str}.rb" | ||
puts " - lib/input/day_#{day_str}.txt" | ||
puts " - spec/solutions/day_#{day_str}_spec.rb" | ||
puts " - spec/input/day_#{day_str}_test.txt" | ||
end | ||
|
||
if ARGV.empty? | ||
puts "Usage: bin/generate DAY" | ||
puts "Example: bin/generate 1" | ||
exit 1 | ||
end | ||
|
||
day = ARGV[0].to_i | ||
create_day(day) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'fileutils' | ||
|
||
class AdventOfCode2024 | ||
def self.run(day) | ||
day_str = day.to_s.rjust(2, '0') | ||
day_file = File.join(__dir__, 'solutions', "day_#{day_str.downcase}.rb") | ||
|
||
begin | ||
require day_file | ||
solution_class = Object.const_get("Day#{day_str}") | ||
|
||
input = File.read( | ||
File.join(__dir__, 'input', "day_#{day_str}.txt") | ||
).strip | ||
|
||
puts "Part 1: #{solution_class.new.part_one(input)}" | ||
puts "Part 2: #{solution_class.new.part_two(input)}" | ||
rescue LoadError | ||
puts "Error: Could not find solution file for day #{day_str}" | ||
rescue NameError | ||
puts "Error: Could not find Day#{day_str} class in solution file" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'rspec/expectations' | ||
require_relative '../lib/application' | ||
|
||
RSpec.configure do |config| | ||
config.expect_with :rspec do |expectations| | ||
expectations.include_chain_clauses_in_custom_matcher_descriptions = true | ||
end | ||
|
||
config.mock_with :rspec do |mocks| | ||
mocks.verify_partial_doubles = true | ||
end | ||
|
||
config.shared_context_metadata_behavior = :apply_to_host_groups | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Day%{day} | ||
def part_one(input) | ||
input.split("\n").map(&:to_i).sum | ||
end | ||
|
||
def part_two(input) | ||
0 | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require "spec_helper" | ||
require "solutions/day_%{day}" | ||
|
||
RSpec.describe Day%{day} do | ||
let(:input) { File.read(File.join(__dir__, '..', '..', 'spec', 'input', 'day_%{day}_test.txt')).strip } | ||
|
||
describe '#part_one' do | ||
it 'calculates the correct solutions for part one' do | ||
expect(subject.part_one(input)).to eq(0) | ||
end | ||
end | ||
|
||
describe '#part_two' do | ||
it 'calculates the correct solutions for part two' do | ||
expect(subject.part_two(input)).to eq(0) | ||
end | ||
end | ||
end | ||
|