2
1
Fork 0

Day 2: Lua: Less syntactic salt

This commit is contained in:
Mia Herkt 2021-12-02 19:15:36 +01:00
parent d6bf929fc8
commit 91c74473a8
Signed by: mia
GPG Key ID: 72E154B8622EC191
2 changed files with 4 additions and 4 deletions

View File

@ -8,8 +8,8 @@ function up(val) v = v - val end
function forward(val) h = h + val end
for line in io.lines("input.txt") do
cmd, val = line:gmatch("(%S+) (%S+)")()
cmd, val = string.match(line, "(%S+) (%S+)")
_G[cmd](val)
end
print(("Answer: %d"):format(h * v))
print(string.format("Answer: %d", h * v))

View File

@ -9,8 +9,8 @@ function up(val) aim = aim - val end
function forward(val) h = h + val; v = v + aim * val end
for line in io.lines("input.txt") do
cmd, val = line:gmatch("(%S+) (%S+)")()
cmd, val = string.match(line, "(%S+) (%S+)")
_G[cmd](val)
end
print(("Answer: %d"):format(h * v))
print(string.format("Answer: %d", h * v))