day 21 part 1

This commit is contained in:
Felix Van der Jeugt 2021-12-21 08:26:42 +01:00
parent fadc49c09d
commit 7d7581dff9
No known key found for this signature in database
GPG Key ID: 58B209295023754D

26
day21/part1.lua Executable file
View File

@ -0,0 +1,26 @@
#!/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)