diff options
| author | Juan Marín Noguera <juan@mnpi.eu> | 2024-12-01 14:29:18 +0100 |
|---|---|---|
| committer | Juan Marín Noguera <juan@mnpi.eu> | 2024-12-01 14:29:18 +0100 |
| commit | 47eb33e373f0b6fe9891b786e8ba3951fc41476a (patch) | |
| tree | 5364e8342d176c0d33a3f0e4e7c66189cb5ff3a5 /main | |
| parent | f4327e7fb94a6a7621941c3d447f7270d59db357 (diff) | |
Day 01
This also includes a template to call the relevant functions from each
day more conveniently.
Diffstat (limited to 'main')
| -rwxr-xr-x | main | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -0,0 +1,29 @@ +#!/usr/bin/lua + +if #arg < 1 or #arg > 2 then + error ("Syntax: %s <DAY><a|b> [inputfile]"):format(arg[0]) + os.exit(1) +end + +local num, letter = arg[1]:match("^(%d+)([ab])$") +if not num then + error ('Expected <DAY><a|b> as first argument (e.g. "01b"), got: %s'):format(arg[1]) + os.exit(1) +end +num = tonumber(num) + +local script = ("%02d.lua"):format(num) +local infile = arg[2] or ("%02d.in"):format(num) +local input_stream = io.open(infile) +if input_stream then + io.input(input_stream) +else + print "Reading from standard input." +end + +local parsed = loadfile(script)() +if letter == 'a' then + parsed:part1() +else + parsed:part2() +end |
