-
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.
Add script to generate the files for a day/today
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require_relative '../lib/aoc' | ||
|
||
module Day<%= str_day %> | ||
extend AOC::Day | ||
|
||
@num = <%= day %> | ||
@ans_test1 = -1 | ||
@ans_test2 = -1 | ||
|
||
def self.solve_part1(input) | ||
return 0 | ||
end | ||
|
||
def self.solve_part2(input) | ||
return 0 | ||
end | ||
end | ||
|
||
Day<%= str_day %>.run |
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,37 @@ | ||
require 'date' | ||
require 'erb' | ||
|
||
# Select and validate day number | ||
day = Date.today.strftime("%d").to_i | ||
if ARGV.length > 0 | ||
day = ARGV[0].to_i | ||
end | ||
if day < 1 or day > 25 | ||
puts "Usage: #{File.basename($0)} [day_number]" | ||
exit | ||
end | ||
|
||
puts "Generating files for day #{day}..." | ||
|
||
str_day = "%02d" % day | ||
base_dir = File.join(File.expand_path(".")) | ||
|
||
# Check if the files for this day already exists, do not overwrite! | ||
day_path = File.join(base_dir, "days", "day#{str_day}.rb") | ||
if File.exist?(day_path) | ||
puts "The files for this day already exist" | ||
exit | ||
end | ||
|
||
# Generate solution file from template | ||
tpl_file = File.read(File.join(base_dir, "tools", "day_template.erb")) | ||
tpl = ERB.new(tpl_file) | ||
File.write(day_path, tpl.result(binding)) | ||
puts "Created solution file" | ||
|
||
# Generate test_input file | ||
test_path = File.join(base_dir, "inputs", "test", "test_input#{str_day}") | ||
File.write(test_path, "") | ||
puts "Created empty test file" | ||
|
||
puts "Done" |