commit 4f14f9b5afe0a90c0b36d84a7f5f2ded9ffcf864 Author: Guillaume Dott Date: Thu Dec 1 11:53:19 2022 +0100 First commit diff --git a/common.rb b/common.rb new file mode 100644 index 0000000..d12c5bc --- /dev/null +++ b/common.rb @@ -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 diff --git a/init-day.sh b/init-day.sh new file mode 100755 index 0000000..8753d5c --- /dev/null +++ b/init-day.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +BASEDIR=$(dirname "$0") + +if [ ! -z "$1" ] +then + DAY=$(printf "%02d" "$1") +else + DAY=$(date +%d) +fi + +if [ ! -d $DAY ] +then + mkdir $DAY +fi + +if [ ! -f $DAY/script.rb ] +then + sed "s/NB/$DAY/" $BASEDIR/template.rb >$DAY/script.rb + chmod +x $DAY/script.rb +fi + +vim $DAY/script.rb diff --git a/template.rb b/template.rb new file mode 100755 index 0000000..fbce6ca --- /dev/null +++ b/template.rb @@ -0,0 +1,13 @@ +#!/usr/bin/env ruby + +require_relative '../common' + +class DayNB < Day + def part1 + end + + def part2 + end +end + +DayNB.run