17 lines
314 B
Lua
17 lines
314 B
Lua
|
#!/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
|
||
|
cmd, val = line:gmatch("(%S+) (%S+)")()
|
||
|
_G[cmd](val)
|
||
|
end
|
||
|
|
||
|
print(("Answer: %d"):format(h * v))
|