Skip to content

Commit

Permalink
Add script to generate the files for a day/today
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeilko committed Dec 9, 2023
1 parent 7edb8e3 commit 0ad7321
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tools/day_template.erb
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
37 changes: 37 additions & 0 deletions tools/generate_files.rb
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"

0 comments on commit 0ad7321

Please sign in to comment.