-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
40 lines (31 loc) · 1.1 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
-- lua-string breaks the parsing in http if required before http, so we make sure to (indirectly) require
-- http here before ever requiring lua-string
local client = require("client")
-- Some convenience for the puzzles
table.__index = table
local function main(day)
if day and not day:match("^%d+$") then
print("Parameter 1 must be a number, if it's present.")
return
elseif not day then
day = os.date("*t").day
end
local ok, puzzles = pcall(require, "day-" .. day)
if not ok then
local err = puzzles
print(("There's no solution for day '%s' (yet): %s"):format(day, err))
return
end
local ok, err = pcall(puzzles.init, puzzles, day)
if not ok then
print(("Initialization of day %s failed: %s"):format(day, err))
return
end
print(("Answer for day %s, puzzle 1: %s"):format(day, puzzles:puzzle1()))
if puzzles.puzzle2 then
print(("Answer for day %s, puzzle 2: %s"):format(day, puzzles:puzzle2()))
else
print(("There's no solution for day %s, puzzle 2 yet."):format(day))
end
end
main(...)