aboutsummaryrefslogtreecommitdiff
path: root/run
diff options
context:
space:
mode:
authorNat Lasseter <Nat Lasseter nathan@bytemark.co.uk>2017-12-01 11:57:19 +0000
committerNat Lasseter <Nat Lasseter nathan@bytemark.co.uk>2017-12-01 11:57:19 +0000
commit2e15fbd3a5baaefbd325453f965eb58c7b56be76 (patch)
treeb2cf8111a0cced007b35bf7ee3cc483d8d1273ec /run
Initial commit, day01
Diffstat (limited to 'run')
-rwxr-xr-xrun41
1 files changed, 41 insertions, 0 deletions
diff --git a/run b/run
new file mode 100755
index 0000000..38d0f0e
--- /dev/null
+++ b/run
@@ -0,0 +1,41 @@
+#!/usr/bin/env ruby
+
+arg = (ARGV.first || "").chomp.downcase
+
+def run(day)
+ puts "Day #{day[3..4]}:"
+
+ runpart(day, 1) if File.exists?("#{day}/part1")
+ runpart(day, 2) if File.exists?("#{day}/part2")
+end
+
+def runpart(day, part)
+ print " Part #{part}: "
+ if File.exists?("#{day}/part#{part}.input") then
+ puts `#{day}/part#{part} < #{day}/part#{part}.input`
+ elsif File.exists?("#{day}/input") then
+ puts `#{day}/part#{part} < #{day}/input`
+ else
+ puts "Missing input file"
+ end
+end
+
+if arg != "" then
+ if arg == "all" then
+ #run all
+ days = Dir.entries('.').select{|d|d=~/^day/}
+ days.each do |day|
+ run day
+ end
+ else
+ #run specified day
+ arg = arg.to_i
+ day = "day%02d" % arg
+ run day
+ end
+else
+ #run today
+ arg = Time.now.day
+ day = "day%02d" % arg
+ run day
+end