This commit is contained in:
ame 2023-12-06 22:25:45 -06:00
parent 84e948f276
commit 060705601b
3 changed files with 86 additions and 0 deletions

3
src/6.input Normal file
View File

@ -0,0 +1,3 @@
Time: 54 81 70 88
Distance: 446 1292 1035 1007

43
src/6p1.lua Normal file
View File

@ -0,0 +1,43 @@
require "llib"
local inp = llib.io.readfile("6.input")
local lines = {}
for s in inp:gmatch("[^\r\n]+") do
table.insert(lines, s.." ")
end
local function get_row(ind)
local tfun = {}
local nnum = ""
for i=1,string.len(lines[ind]) do
local c = string.sub(lines[ind],i,i)
if c == ' ' then
if tonumber(nnum) ~= nil then
table.insert(tfun, tonumber(nnum))
end
nnum = ""
else
nnum = nnum .. c
end
end
return tfun
end
local times = get_row(1)
local highscores = get_row(2)
local total = 1
for i=1,#times do
local better = 0
for z=1,times[i] - 1 do
if z*(times[i]-z) > highscores[i] then
better = better + 1
end
end
if better ~= 0 then
total = total * better
end
end
print(total)

40
src/6p2.lua Normal file
View File

@ -0,0 +1,40 @@
require "llib"
local inp = llib.io.readfile("6.input")
local lines = {}
for s in inp:gmatch("[^\r\n]+") do
table.insert(lines, s.." ")
end
local function get_row(ind)
local tfun = 0
local nnum = ""
for i=1,string.len(lines[ind]) do
local c = string.sub(lines[ind],i,i)
if c == ' ' then
if tonumber(nnum) ~= nil then
tfun = tfun * 10^string.len(nnum) + nnum
end
nnum = ""
else
nnum = nnum .. c
end
end
--print(tfun)
return tfun
end
local times = get_row(1)
local highscores = get_row(2)
--os.exit(0)
local better = 0
for z=1,times - 1 do
--print(z*(times[i]-z))
if z*(times-z) > highscores then
better = better + 1
end
end
print(better)