diff options
| author | Juan Marín Noguera <juan@mnpi.eu> | 2024-12-05 13:24:52 +0100 |
|---|---|---|
| committer | Juan Marín Noguera <juan@mnpi.eu> | 2024-12-05 13:24:52 +0100 |
| commit | 84c986dffe7a85c87b80e6d736b3b36e460ff4dd (patch) | |
| tree | 026e817a43a6a55e4fae4c1193e3945eb43e7b53 /main.lua | |
| parent | 06b1f2b0f5d84958897d39e85d099e4e8cce4546 (diff) | |
Update instructions to apply to Guile
Also rename `main` to `main.lua` and `main.scm` to `main`.
Diffstat (limited to 'main.lua')
| -rwxr-xr-x | main.lua | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/main.lua b/main.lua new file mode 100755 index 0000000..38189ee --- /dev/null +++ b/main.lua @@ -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 |
