first version of aoc helper
commit
cee9087661
|
@ -0,0 +1 @@
|
|||
3.1.2
|
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
source "https://rubygems.org"
|
||||
|
||||
gem 'tty-prompt'
|
||||
gem 'tty-file'
|
||||
gem "colorize", "~> 0.8.1"
|
|
@ -0,0 +1,33 @@
|
|||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
colorize (0.8.1)
|
||||
diff-lcs (1.5.0)
|
||||
pastel (0.8.0)
|
||||
tty-color (~> 0.5)
|
||||
tty-color (0.6.0)
|
||||
tty-cursor (0.7.1)
|
||||
tty-file (0.10.0)
|
||||
diff-lcs (~> 1.3)
|
||||
pastel (~> 0.8)
|
||||
tty-prompt (~> 0.22)
|
||||
tty-prompt (0.23.1)
|
||||
pastel (~> 0.8)
|
||||
tty-reader (~> 0.8)
|
||||
tty-reader (0.9.0)
|
||||
tty-cursor (~> 0.7)
|
||||
tty-screen (~> 0.8)
|
||||
wisper (~> 2.0)
|
||||
tty-screen (0.8.1)
|
||||
wisper (2.0.1)
|
||||
|
||||
PLATFORMS
|
||||
arm64-darwin-21
|
||||
|
||||
DEPENDENCIES
|
||||
colorize (~> 0.8.1)
|
||||
tty-file
|
||||
tty-prompt
|
||||
|
||||
BUNDLED WITH
|
||||
2.3.22
|
|
@ -0,0 +1,16 @@
|
|||
require "tty-prompt"
|
||||
require_relative "tasks/new_day"
|
||||
require_relative "tasks/part_two"
|
||||
|
||||
prompt = TTY::Prompt.new
|
||||
|
||||
day = prompt.ask("Name the day (1-24)") do |q|
|
||||
q.in("1-24")
|
||||
end
|
||||
selected = prompt.select("What do you want to do", "New day":0, "Add part 2 to a day":1)
|
||||
|
||||
if selected == 0
|
||||
new_day(prompt, day)
|
||||
elsif selected == 1
|
||||
part_two(prompt, day)
|
||||
end
|
|
@ -0,0 +1,21 @@
|
|||
require "tty-prompt"
|
||||
require "tty-file"
|
||||
require "ostruct"
|
||||
|
||||
def new_day(prompt, day)
|
||||
input = prompt.multiline("Example input").join("")
|
||||
print input
|
||||
result = prompt.ask("Example result")
|
||||
|
||||
day_name = "day_#{day}"
|
||||
|
||||
TTY::File.copy_directory("app/templates","#{day_name}")
|
||||
|
||||
TTY::File.replace_in_file "#{day_name}/run.rb", /%day_name%/, day_name
|
||||
TTY::File.replace_in_file "#{day_name}/test.rb", /%day_name%/, day_name
|
||||
TTY::File.replace_in_file "#{day_name}/test.rb", /%example_result%/, result
|
||||
TTY::File.replace_in_file "#{day_name}/test.rb", /%example_input%/, input
|
||||
|
||||
puts "Done - run with:"
|
||||
puts "ruby #{day_name}/test.rb"
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
require "tty-prompt"
|
||||
|
||||
def part_two(prompt, day)
|
||||
prompt.say("part two not yet supported")
|
||||
end
|
|
@ -0,0 +1,17 @@
|
|||
#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
|
|
@ -0,0 +1,19 @@
|
|||
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
|
|
@ -0,0 +1,22 @@
|
|||
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
|
Loading…
Reference in New Issue