Add base files

main
Guillaume Dott 2021-12-01 14:56:21 +01:00
commit aa1a08be1c
3 changed files with 79 additions and 0 deletions

44
common.rb 100644
View File

@ -0,0 +1,44 @@
class Input
FILE = 'input'
def initialize(directory, file = nil)
@filename = "#{directory}/#{file || FILE}"
end
def readlines
File.readlines(@filename).reject { |line| line.start_with?('#') }
end
end
class Day
def self.run
new.run
end
def part1
end
def part2
end
def run
puts "=== Part 1 ==="
puts part1
puts "=== Part 2 ==="
puts part2
end
private
def filename
"#{File.dirname($PROGRAM_NAME)}/input"
end
def input
@input ||= if File.exist?(filename)
File.readlines(filename).reject { |line| line.start_with?('#') }.map(&:chomp)
else
INPUT
end
end
end

22
init-day.sh 100755
View File

@ -0,0 +1,22 @@
#!/bin/sh
BASEDIR=$(dirname "$0")
if [ ! -z "$1" ]
then
DAY=$(printf "%02d" "$1")
else
DAY=$(date +%d)
fi
cd $BASEDIR/
if [ ! -d $DAY ]
then
mkdir $DAY
fi
if [ ! -f $DAY/script.rb ]
then
sed "s/NB/$DAY/" template.rb >$DAY/script.rb
fi

13
template.rb 100755
View File

@ -0,0 +1,13 @@
#!/usr/bin/env ruby
require_relative '../common'
class DayNB < Day
def part1
end
def part2
end
end
DayNB.run