2
1
Fork 0
aoc2021/02/solution_2.lua

17 lines
325 B
Lua
Raw Normal View History

2021-12-02 12:43:26 +01:00
#!/usr/bin/env lua
aim = 0
h = 0
v = 0
function down(val) aim = aim + val end
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
2021-12-02 19:15:36 +01:00
cmd, val = string.match(line, "(%S+) (%S+)")
2021-12-02 12:43:26 +01:00
_G[cmd](val)
end
2021-12-02 19:15:36 +01:00
print(string.format("Answer: %d", h * v))