adventofcode-2021/day21/part1.lua

27 lines
562 B
Lua
Raw Normal View History

2021-12-21 08:26:42 +01:00
#!/usr/bin/env luajit
require("utils")
local f = io.open(arg[3])
local fst = string.match(f:read("*l"), "Player 1 starting position: (.*)")
local snd = string.match(f:read("*l"), "Player 2 starting position: (.*)")
f:close()
function rolls()
local i = 0
return function()
i = i + 1
return i
end
end
local r = rolls()
local turn = 0
local fstscore, sndscore = 0, 0
repeat
snd, fst = (fst + r() + r() + r() - 1) % 10 + 1, snd
sndscore, fstscore = fstscore + snd, sndscore
turn = turn + 3
until sndscore >= 1000
print(fstscore, turn, fstscore * turn)