From 0ad732176ab34c682a9efb3389a84a9daa8895f3 Mon Sep 17 00:00:00 2001 From: Aeilko Bos Date: Sat, 9 Dec 2023 15:09:45 +0100 Subject: [PATCH] Add script to generate the files for a day/today --- tools/day_template.erb | 19 +++++++++++++++++++ tools/generate_files.rb | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 tools/day_template.erb create mode 100644 tools/generate_files.rb diff --git a/tools/day_template.erb b/tools/day_template.erb new file mode 100644 index 0000000..80d1b40 --- /dev/null +++ b/tools/day_template.erb @@ -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 diff --git a/tools/generate_files.rb b/tools/generate_files.rb new file mode 100644 index 0000000..6e396e9 --- /dev/null +++ b/tools/generate_files.rb @@ -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"