aoc_rb 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 076dd89dac44c23506bbb8246e31461f1c368b80641e5ffcb6fd1bdf61ddfb88
4
- data.tar.gz: 976bd57bcd1cc83e82374daf596f4c8225915c55aea4550dc443194e0fe16c92
3
+ metadata.gz: 38ac165e5227f5d9b076d64d93dea19911b340dc9d5548d09f5ae5cb212bc6db
4
+ data.tar.gz: ca88a6b53beea0f7494a48ec17ba26314b9d87c37f22ddeb32d8b4fb782ebfef
5
5
  SHA512:
6
- metadata.gz: 4cf7d655b9f0abf9fbcb510401398c2a579d7695b7bac06d89285a94549e94f7a382801b6cc765f1765c8d7c48f60c5330119a2bf89d35224bab536a76aa9262
7
- data.tar.gz: faa35ceb5476c8df89d3cd84c5d423e62d652e216f17bd79b666d96f2f58d4400f3da682f1009b0b4687c2b026226e6bcf196303ebca04f4db5065e048216c91
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
- src_files = File.join(Dir.getwd, "challenges", "**", "*.rb")
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}", input) }
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
- answer = level == 1 ? puzzle.part_1(input) : puzzle.part_2(input)
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'])
@@ -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
@@ -1,3 +1,3 @@
1
1
  module AocRb
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,12 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
  module Year<%= @year %>
3
- class Day<%= @day %>
4
- def part_1(input)
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(input)
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(puzzle.part_1(example_input)).to eq(nil)
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(puzzle.part_1(input)).to eq(nil)
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(puzzle.part_2(example_input)).to eq(nil)
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(puzzle.part_2(input)).to eq(nil)
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.1.1
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-01 00:00:00.000000000 Z
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