aoc_rb 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/aoc_rb/app.rb +11 -3
- data/lib/aoc_rb/cli.rb +6 -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 +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38ac165e5227f5d9b076d64d93dea19911b340dc9d5548d09f5ae5cb212bc6db
|
4
|
+
data.tar.gz: ca88a6b53beea0f7494a48ec17ba26314b9d87c37f22ddeb32d8b4fb782ebfef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '03981012538cc9f76c88e32b1ba4d7cf3c0f51101da979065e84ea22ce8f7a12fcd45eb9d7f2451d8a044b0352150b73a94efa6bba99700e3c4f797c211aac6d'
|
7
|
+
data.tar.gz: 6ff40d3a21324bcad2f840583ad9e9bb1388e84c852ae268580c343c04254775fbfcf50280767fb3841f586f874f07a2d21bf18fd5d7faf4ee6951e6a624c560
|
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
@@ -22,6 +22,12 @@ module AocRb
|
|
22
22
|
FileUtils.mkdir_p bin_dir
|
23
23
|
File.open(bin_path, "w") { |f| f.write(File.read(bin_template)) }
|
24
24
|
|
25
|
+
shared_dir = File.join(project_dir, "challenges", "shared")
|
26
|
+
solution_path = File.join(shared_dir, "solution.rb")
|
27
|
+
solution_template = File.join(File.dirname(__FILE__), "../../templates/solution_base.rb")
|
28
|
+
FileUtils.mkdir_p shared_dir
|
29
|
+
File.open(solution_path, "w") { |f| f.write(File.read(solution_template)) }
|
30
|
+
|
25
31
|
spec_dir = File.join(project_dir, "spec")
|
26
32
|
spec_helper_path = File.join(spec_dir, "spec_helper.rb")
|
27
33
|
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.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Pascoe
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|
@@ -130,6 +130,7 @@ files:
|
|
130
130
|
- templates/Gemfile
|
131
131
|
- templates/bin/aoc
|
132
132
|
- templates/solution.rb.erb
|
133
|
+
- templates/solution_base.rb
|
133
134
|
- templates/solution_spec.rb.erb
|
134
135
|
- templates/spec/spec_helper.rb
|
135
136
|
homepage: https://github.com/pacso/aoc_rb
|