aoc-helper/lib/tasks/templates.rb

67 lines
1015 B
Ruby
Raw Normal View History

2022-12-02 19:42:16 +01:00
TEST_RB = <<~'TEST'
require_relative "impl"
INPUT = <<~IN
%example_input%
IN
RESULT = %example_result%
def test_example
parsed = parse(INPUT)
result = calculate(parsed)
if result == RESULT
puts "Test successful. Now run with real input"
puts "ruby %day_name%/run.rb"
else
puts "Test failed"
puts "expected \"#{RESULT}\" got \"#{result}\""
end
end
test_example
TEST
RUN_RB = <<~'RUN'
require_relative "impl"
def print(result)
if result.is_a? Array
result.map! {|l| "#{l}\n" }
end
puts result
end
def run
puts "running your implementation"
input = File.new("%day_name%/data").read
data = parse(input)
result = calculate(data)
print(result)
end
run
RUN
IMPL_RB = <<~'IMPL'
#prepare the input which is a string containing new lines
def parse(input)
data = []
input.each_line do |line|
data << line
end
data
end
# result should a single string or integer
def calculate(data)
result = ""
data.each do |d|
result = d
end
result
end
IMPL