aoc_rb 0.1.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +13 -4
- data/CHANGELOG.md +25 -0
- data/lib/aoc_rb/app.rb +11 -3
- data/lib/aoc_rb/cli.rb +7 -0
- data/lib/aoc_rb/puzzle_solution.rb +2 -2
- data/lib/aoc_rb/puzzle_source.rb +2 -2
- data/lib/aoc_rb/version.rb +1 -1
- data/templates/solution.rb.erb +17 -3
- data/templates/solution_base.rb +34 -0
- data/templates/solution_spec.rb.erb +4 -5
- data/templates/spec/spec_helper.rb +5 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03b8a728ae0c5b35a43fc4a6c84c178820c71bc216682fd4998f4fa4aa3f713f
|
4
|
+
data.tar.gz: 5f3286c76bf28ae59b9247a8b537fa3f1f642cc0ff3752bec90ccd71d34650d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6c6be37087f9ba31bc68a1d317a3215fda3786787cd6c908cfa59a459c98bd1713a59129e583459396768780e2b4564895c7261058f23cd1026881414e89deb
|
7
|
+
data.tar.gz: fbb164d72c20009d22ada48ac5bd7731418581c7ee4db3733cb4488c6c29fdd3c7cd56927637009f9faf32385533f4fdd0f9f9ed4cd478bfc766c9a02aa34664
|
data/.github/workflows/tests.yml
CHANGED
@@ -14,20 +14,29 @@ on:
|
|
14
14
|
branches: [ main ]
|
15
15
|
|
16
16
|
jobs:
|
17
|
+
changelog:
|
18
|
+
runs-on: ubuntu-latest
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v2
|
21
|
+
- id: read-version
|
22
|
+
run: |
|
23
|
+
echo "::set-output name=VERSION::`cat lib/aoc_rb/version.rb | grep -i version | awk '{ print $3 }' | sed -e 's/\"//g'`"
|
24
|
+
- uses: dangoslen/changelog-enforcer@v2.3.1
|
25
|
+
with:
|
26
|
+
skipLabels: 'skip-changelog'
|
27
|
+
expectedLatestVersion: ${{ steps.read-version.outputs.VERSION }}
|
17
28
|
test:
|
18
|
-
|
19
29
|
runs-on: ubuntu-latest
|
20
30
|
strategy:
|
21
31
|
matrix:
|
22
|
-
ruby-version: ['2.6', '2.7', '3.0']
|
23
|
-
|
32
|
+
ruby-version: ['2.6', '2.7', '3.0', '3.1']
|
24
33
|
steps:
|
25
34
|
- uses: actions/checkout@v2
|
26
35
|
- name: Set up Ruby
|
27
36
|
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
28
37
|
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
29
38
|
# uses: ruby/setup-ruby@v1
|
30
|
-
uses: ruby/setup-ruby@
|
39
|
+
uses: ruby/setup-ruby@ebaea52cb20fea395b0904125276395e37183dac
|
31
40
|
with:
|
32
41
|
ruby-version: ${{ matrix.ruby-version }}
|
33
42
|
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [0.2.2]
|
8
|
+
### Fixed
|
9
|
+
- FileUtils uninitialized constant bug ([#10](https://github.com/pacso/aoc_rb/pull/10))
|
10
|
+
|
11
|
+
## [0.2.1]
|
12
|
+
|
13
|
+
## [0.2.0]
|
14
|
+
|
15
|
+
## [0.1.0]
|
16
|
+
|
17
|
+
## [0.0.0]
|
18
|
+
|
19
|
+
Initial release.
|
20
|
+
|
21
|
+
[Unreleased]: https://github.com/pacso/aoc_rb/compare/v0.2.2...HEAD
|
22
|
+
[0.2.2]: https://github.com/pacso/aoc_rb/compare/v0.2.1...v0.2.2
|
23
|
+
[0.2.1]: https://github.com/pacso/aoc_rb/compare/v0.2.0...v0.2.1
|
24
|
+
[0.2.0]: https://github.com/pacso/aoc_rb/compare/v0.1.0...v0.2.0
|
25
|
+
[0.1.0]: https://github.com/pacso/aoc_rb/compare/v0.0.0...v0.1.0
|
data/lib/aoc_rb/app.rb
CHANGED
@@ -9,8 +9,16 @@ require 'aoc_rb/puzzle_input'
|
|
9
9
|
require 'aoc_rb/puzzle_solution'
|
10
10
|
require 'aoc_rb/puzzle_source'
|
11
11
|
|
12
|
-
|
12
|
+
shared_files = File.join(Dir.getwd, "challenges", "shared", "**", "*.rb")
|
13
|
+
Dir[shared_files].each do |file|
|
14
|
+
if File.exist? file
|
15
|
+
require file
|
16
|
+
else
|
17
|
+
puts "missing file #{file}"
|
18
|
+
end
|
19
|
+
end
|
13
20
|
|
21
|
+
src_files = File.join(Dir.getwd, "challenges", "20**", "**", "*.rb")
|
14
22
|
Dir[src_files].each do |file|
|
15
23
|
if File.exist? file
|
16
24
|
require file
|
@@ -72,12 +80,12 @@ module AocRb
|
|
72
80
|
method_option :day, aliases: "-d", type: :numeric, default: Time.now.day
|
73
81
|
|
74
82
|
def exec(year = options[:year], day = options[:day])
|
75
|
-
puzzle = AocRb::PuzzleSource.create_puzzle(year, day)
|
76
83
|
input = AocRb::PuzzleInput.load(year, day)
|
84
|
+
puzzle = AocRb::PuzzleSource.create_puzzle(year, day, input)
|
77
85
|
|
78
86
|
level = Puzzle.instructions_exist?(year, day, :part_2) ? 2 : 1
|
79
87
|
puts "#{year} Day #{day}"
|
80
|
-
solution = PuzzleSource.run_part("part #{level}") { puzzle.send("part_#{level}"
|
88
|
+
solution = PuzzleSource.run_part("part #{level}") { puzzle.send("part_#{level}") }
|
81
89
|
|
82
90
|
puts "Submit solution? #{solution} (y/N)"
|
83
91
|
submit = STDIN.gets.chomp.downcase
|
data/lib/aoc_rb/cli.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "fileutils"
|
3
4
|
require "aoc_rb/app_loader"
|
4
5
|
AocRb::AppLoader.exec_app
|
5
6
|
|
@@ -22,6 +23,12 @@ module AocRb
|
|
22
23
|
FileUtils.mkdir_p bin_dir
|
23
24
|
File.open(bin_path, "w") { |f| f.write(File.read(bin_template)) }
|
24
25
|
|
26
|
+
shared_dir = File.join(project_dir, "challenges", "shared")
|
27
|
+
solution_path = File.join(shared_dir, "solution.rb")
|
28
|
+
solution_template = File.join(File.dirname(__FILE__), "../../templates/solution_base.rb")
|
29
|
+
FileUtils.mkdir_p shared_dir
|
30
|
+
File.open(solution_path, "w") { |f| f.write(File.read(solution_template)) }
|
31
|
+
|
25
32
|
spec_dir = File.join(project_dir, "spec")
|
26
33
|
spec_helper_path = File.join(spec_dir, "spec_helper.rb")
|
27
34
|
spec_helper_template = File.join(File.dirname(__FILE__), "../../templates/spec/spec_helper.rb")
|
@@ -6,9 +6,9 @@ module AocRb
|
|
6
6
|
|
7
7
|
def submit(level, year, day, answer = nil, allow_waiting = true)
|
8
8
|
if answer.nil?
|
9
|
-
puzzle = PuzzleSource.create_puzzle(year, day)
|
10
9
|
input = PuzzleInput.load(year, day)
|
11
|
-
|
10
|
+
puzzle = PuzzleSource.create_puzzle(year, day, input)
|
11
|
+
answer = level == 1 ? puzzle.part_1 : puzzle.part_2
|
12
12
|
end
|
13
13
|
|
14
14
|
aoc_api = AocApi.new(ENV['AOC_COOKIE'])
|
data/lib/aoc_rb/puzzle_source.rb
CHANGED
@@ -5,10 +5,10 @@ module AocRb
|
|
5
5
|
module PuzzleSource
|
6
6
|
extend self
|
7
7
|
|
8
|
-
def create_puzzle(year, day)
|
8
|
+
def create_puzzle(year, day, input)
|
9
9
|
padded_day = Puzzle.padded(day)
|
10
10
|
begin
|
11
|
-
Module.const_get("Year#{year}").const_get("Day#{padded_day}").new
|
11
|
+
Module.const_get("Year#{year}").const_get("Day#{padded_day}").new(input)
|
12
12
|
rescue NameError
|
13
13
|
puts "There is no solution for this puzzle"
|
14
14
|
end
|
data/lib/aoc_rb/version.rb
CHANGED
data/templates/solution.rb.erb
CHANGED
@@ -1,12 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Year<%= @year %>
|
3
|
-
class Day<%= @day %>
|
4
|
-
|
3
|
+
class Day<%= @day %> < Solution
|
4
|
+
# @input is available if you need the raw data input
|
5
|
+
# Call `data` to access either an array of the parsed data, or a single record for a 1-line input file
|
6
|
+
|
7
|
+
def part_1
|
5
8
|
nil
|
6
9
|
end
|
7
10
|
|
8
|
-
def part_2
|
11
|
+
def part_2
|
9
12
|
nil
|
10
13
|
end
|
14
|
+
|
15
|
+
private
|
16
|
+
# Processes each line of the input file and stores the result in the dataset
|
17
|
+
# def process_input(line)
|
18
|
+
# line.map(&:to_i)
|
19
|
+
# end
|
20
|
+
|
21
|
+
# Processes the dataset as a whole
|
22
|
+
# def process_dataset(set)
|
23
|
+
# set
|
24
|
+
# end
|
11
25
|
end
|
12
26
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true %>
|
2
|
+
|
3
|
+
class Solution
|
4
|
+
def self.part_1(*input)
|
5
|
+
new(*input).part_1
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.part_2(*input)
|
9
|
+
new(*input).part_2
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(input)
|
13
|
+
@input = input
|
14
|
+
end
|
15
|
+
|
16
|
+
def data
|
17
|
+
@data ||= begin
|
18
|
+
processed = @input.lines(chomp: true).map do |line|
|
19
|
+
process_input line
|
20
|
+
end
|
21
|
+
|
22
|
+
processed.length == 1 ? processed.first : process_dataset(processed)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def process_input(line)
|
28
|
+
line
|
29
|
+
end
|
30
|
+
|
31
|
+
def process_dataset(set)
|
32
|
+
set
|
33
|
+
end
|
34
|
+
end
|
@@ -2,7 +2,6 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
RSpec.describe Year<%= @year %>::Day<%= @day %> do
|
5
|
-
let(:puzzle) { Year<%= @year %>::Day<%= @day %>.new }
|
6
5
|
let(:input) { File.read(File.join(File.dirname(__FILE__), "../../../challenges/<%= @year %>/<%= @day.to_s.rjust(2, "0") %>/input.txt")) }
|
7
6
|
let(:example_input) {
|
8
7
|
<<~EOF
|
@@ -13,21 +12,21 @@ RSpec.describe Year<%= @year %>::Day<%= @day %> do
|
|
13
12
|
|
14
13
|
describe "part 1" do
|
15
14
|
it "returns nil for the example input" do
|
16
|
-
expect(
|
15
|
+
expect(described_class.part_1(example_input)).to eq(nil)
|
17
16
|
end
|
18
17
|
|
19
18
|
it "returns nil for my input" do
|
20
|
-
expect(
|
19
|
+
expect(described_class.part_1(input)).to eq(nil)
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
24
23
|
describe "part 2" do
|
25
24
|
it "returns nil for the example input" do
|
26
|
-
expect(
|
25
|
+
expect(described_class.part_2(example_input)).to eq(nil)
|
27
26
|
end
|
28
27
|
|
29
28
|
it "returns nil for my input" do
|
30
|
-
expect(
|
29
|
+
expect(described_class.part_2(input)).to eq(nil)
|
31
30
|
end
|
32
31
|
end
|
33
32
|
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
Dir[File.join(File.dirname(__FILE__), "..", "challenges", "**", "*.rb")].each do |file|
|
3
|
+
Dir[File.join(File.dirname(__FILE__), "..", "challenges", "shared", "**", "*.rb")].each do |file|
|
4
|
+
require file
|
5
|
+
end
|
6
|
+
|
7
|
+
Dir[File.join(File.dirname(__FILE__), "..", "challenges", "20*", "**", "*.rb")].each do |file|
|
4
8
|
require file
|
5
9
|
end
|
6
10
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aoc_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Pascoe
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- ".github/workflows/tests.yml"
|
107
107
|
- ".gitignore"
|
108
108
|
- ".rspec"
|
109
|
+
- CHANGELOG.md
|
109
110
|
- CODE_OF_CONDUCT.md
|
110
111
|
- Gemfile
|
111
112
|
- LICENSE
|
@@ -130,6 +131,7 @@ files:
|
|
130
131
|
- templates/Gemfile
|
131
132
|
- templates/bin/aoc
|
132
133
|
- templates/solution.rb.erb
|
134
|
+
- templates/solution_base.rb
|
133
135
|
- templates/solution_spec.rb.erb
|
134
136
|
- templates/spec/spec_helper.rb
|
135
137
|
homepage: https://github.com/pacso/aoc_rb
|
@@ -154,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
156
|
- !ruby/object:Gem::Version
|
155
157
|
version: '0'
|
156
158
|
requirements: []
|
157
|
-
rubygems_version: 3.
|
159
|
+
rubygems_version: 3.3.7
|
158
160
|
signing_key:
|
159
161
|
specification_version: 4
|
160
162
|
summary: A Ruby toolkit for Advent of Code
|