-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday2.lua
47 lines (42 loc) · 796 Bytes
/
day2.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function File_exists(file)
local f = io.open(file, "rb")
if f then
f:close()
end
return f ~= nil
end
function Lines_from(file)
if not File_exists(file) then
return {}
end
local lines = {}
for line in io.lines(file) do
lines[#lines + 1] = line
end
return lines
end
function MySplit(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t = {}
for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
table.insert(t, str)
end
return t
end
local file = "./day2/input"
local lines = Lines_from(file)
local result = 0
for i = 1, #lines, 1 do
local line = MySplit(lines[i])
local previous_number
for v = 1, #line, 1 do
if v == 1 then
previous_number = tonumber(line[v])
else
local step = tonumber(line[v]) - previous_number
end
end
end
print(result)