2022/common.rb

49 lines
798 B
Ruby
Raw Permalink Normal View History

2022-12-01 11:53:19 +01:00
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
2022-12-06 11:59:50 +01:00
def stdin
@stdin ||= ARGF.readlines.reject { |line| line.start_with? "#" }.map(&:chomp)
end
2022-12-01 11:53:19 +01:00
end