day 21 part 1
This commit is contained in:
parent
fadc49c09d
commit
7d7581dff9
26
day21/part1.lua
Executable file
26
day21/part1.lua
Executable 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)
|
Loading…
Reference in New Issue
Block a user