Compare commits

..

No commits in common. "13851a980c395300ac47dfa4f7615e56281484a8" and "a01d582842545b99f5d2e29154967a4dd47080ae" have entirely different histories.

18 changed files with 12 additions and 268 deletions

View File

@ -1 +0,0 @@
3.1.2

View File

@ -1,6 +0,0 @@
# frozen_string_literal: true
source "https://rubygems.org"
gem 'tty-prompt'
gem 'tty-file'

View File

@ -1,31 +0,0 @@
GEM
remote: https://rubygems.org/
specs:
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
tty-file
tty-prompt
BUNDLED WITH
2.3.22

9
LICENSE Normal file
View File

@ -0,0 +1,9 @@
MIT License
Copyright (c) <year> <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# aoc-helper
little gem with an executable to create templates of the days

Binary file not shown.

View File

@ -1,27 +0,0 @@
# frozen_string_literal: true
Gem::Specification.new do |spec|
spec.name = "aoc-helper"
spec.platform = Gem::Platform::RUBY
spec.version = "0.1.0"
spec.authors = ["Guido Schweizer"]
spec.email = ["guido.schweizer@posteo.de"]
spec.description = %q{helps to create basic folders for aoc}
spec.summary = %q{run aoc and follow instructions}
spec.homepage = "https://aoc.sgui.de"
spec.license = "MIT"
spec.metadata["allowed_push_host"] = "https://rubygems.org"
spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "https://github.com/guidocodes/aoc-helper"
spec.files = Dir.glob("lib/**/*", File::FNM_DOTMATCH)
spec.extra_rdoc_files = ["readme.md", "license.txt"]
spec.bindir = "exe"
spec.executables = ["aoc"]
spec.require_paths = ["lib"]
spec.required_ruby_version = ">= 3.0.0"
spec.add_dependency "tty-file", "~> 0.10"
spec.add_dependency "tty-prompt", "~> 0.23"
end

14
exe/aoc
View File

@ -1,14 +0,0 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
lib_path = File.expand_path('../lib', __dir__)
$:.unshift(lib_path) if !$:.include?(lib_path)
require("aoc")
begin
AOC.run
rescue StandardError => err
puts "ERROR: #{err.message}"
exit 1 #err.status
end

View File

@ -1,20 +0,0 @@
require "tty-prompt"
require_relative "tasks/new_day"
require_relative "tasks/part_two"
class AOC
def self.run
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
end
end

View File

@ -1,27 +0,0 @@
require "tty-prompt"
require "tty-file"
require "ostruct"
require_relative("templates")
def new_day(prompt, day)
input = prompt.multiline("Example input").join("")
print input
result = prompt.ask("Example result")
day_name = "day_#{day}"
TTY::File.create_dir(day_name)
TTY::File.create_file("#{day_name}/data")
TTY::File.create_file("#{day_name}/impl.rb", IMPL_RB)
TTY::File.create_file("#{day_name}/run.rb", RUN_RB)
TTY::File.create_file("#{day_name}/test.rb", TEST_RB)
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

View File

@ -1,5 +0,0 @@
require "tty-prompt"
def part_two(prompt, day)
prompt.say("part two not yet supported")
end

View File

@ -1,67 +0,0 @@
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

View File

@ -1 +0,0 @@
MIT

View File

@ -1,11 +0,0 @@
## Helper for solving Advent of Code days
run `ruby app/main.rb`
name the day
first input is the example input
second input is the examples result
this will generate everything needed to start coding the day
tbd part2

View File

View File

@ -1,17 +0,0 @@
#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

View File

@ -1,19 +0,0 @@
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

View File

@ -1,22 +0,0 @@
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