solved 01-0
This commit is contained in:
parent
3a6d4269b7
commit
d970f97970
50
01-0/main.lua
Executable file
50
01-0/main.lua
Executable file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env lua
|
||||
|
||||
|
||||
|
||||
function file_exists(file)
|
||||
local f = io.open(file, "rb")
|
||||
if f then f:close() end
|
||||
return f ~= nil
|
||||
end
|
||||
|
||||
-- get all lines from a file, returns an empty
|
||||
-- list/table if the file does not exist
|
||||
function lines_from(file)
|
||||
if not file_exists(file) then return {} end
|
||||
lines = {}
|
||||
for line in io.lines(file) do
|
||||
lines[#lines + 1] = line
|
||||
end
|
||||
return lines
|
||||
end
|
||||
|
||||
function atoi_list(strings)
|
||||
local ints = {}
|
||||
for i,s in ipairs(strings) do
|
||||
ints[#ints + 1] = tonumber(s)
|
||||
end
|
||||
return ints
|
||||
end
|
||||
|
||||
-------------------------------------------------
|
||||
file = "input.txt"
|
||||
|
||||
allLines = lines_from(file)
|
||||
allInts = atoi_list(allLines)
|
||||
|
||||
last , counter = 0 , 0;
|
||||
|
||||
last = allInts[1]
|
||||
|
||||
for a,b in ipairs(allInts) do
|
||||
if(a == 1) then
|
||||
else
|
||||
if(last < b) then
|
||||
counter = counter + 1
|
||||
end
|
||||
last = b
|
||||
end
|
||||
end
|
||||
|
||||
io.write("The answer is ", counter, ". Congrats, I hope!\n")
|
Loading…
Reference in New Issue
Block a user