Compare commits
3 Commits
d20e87c963
...
efd650f1cd
| Author | SHA1 | Date | |
|---|---|---|---|
| efd650f1cd | |||
| 05c49abca3 | |||
| 6b90ca82e3 |
@@ -10,7 +10,7 @@
|
|||||||
--
|
--
|
||||||
--
|
--
|
||||||
--local input_file = "test"
|
--local input_file = "test"
|
||||||
local input_file = "full"
|
local input_file = "Day4/full"
|
||||||
local warehouse = {}
|
local warehouse = {}
|
||||||
|
|
||||||
local row = 0
|
local row = 0
|
||||||
|
|||||||
46
2025/Day5/Day5.lua
Normal file
46
2025/Day5/Day5.lua
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
-- Using Autorun now
|
||||||
|
print("Starting Day 5...")
|
||||||
|
|
||||||
|
local input_file = "Day5/full"
|
||||||
|
local Freshness = {
|
||||||
|
Range = {},
|
||||||
|
}
|
||||||
|
|
||||||
|
function Freshness.add(R)
|
||||||
|
local S, E = string.match(R, "(%d+)-(%d+)")
|
||||||
|
local Set = { tonumber(S), tonumber(E) }
|
||||||
|
table.insert(Freshness.Range, Set)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Freshness.show()
|
||||||
|
for k, v in pairs(Freshness.Range) do
|
||||||
|
print(string.format("%d-%d", v[1], v[2]))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Freshness.check(value)
|
||||||
|
cv = tonumber(value)
|
||||||
|
for k, v in pairs(Freshness.Range) do
|
||||||
|
if cv >= v[1] and cv <= v[2] then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local InputMode = true
|
||||||
|
local FreshCounter = 0
|
||||||
|
for line in io.lines(input_file) do
|
||||||
|
if line == "" then
|
||||||
|
InputMode = false
|
||||||
|
elseif InputMode then
|
||||||
|
Freshness.add(line)
|
||||||
|
else
|
||||||
|
if Freshness.check(line) then
|
||||||
|
print("Fresh Item " .. line)
|
||||||
|
FreshCounter = FreshCounter + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
print("Found Fresh Ingredients " .. FreshCounter)
|
||||||
1174
2025/Day5/full
Normal file
1174
2025/Day5/full
Normal file
File diff suppressed because it is too large
Load Diff
11
2025/Day5/test
Normal file
11
2025/Day5/test
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
3-5
|
||||||
|
10-14
|
||||||
|
16-20
|
||||||
|
12-18
|
||||||
|
|
||||||
|
1
|
||||||
|
5
|
||||||
|
8
|
||||||
|
11
|
||||||
|
17
|
||||||
|
32
|
||||||
22
2025/autorun.lua
Normal file
22
2025/autorun.lua
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
-- Use this to get the buffer ID where you want the output
|
||||||
|
-- echo nvim_get_current_buf()
|
||||||
|
vim.api.nvim_create_autocmd("BufWritePost", {
|
||||||
|
group = vim.api.nvim_create_augroup("AutoRunCode", { clear = true }),
|
||||||
|
pattern = "*.lua",
|
||||||
|
callback = function()
|
||||||
|
local bufnr = 21
|
||||||
|
vim.fn.jobstart({ "lua", "Day5/Day5.lua" }, {
|
||||||
|
stdout_buffered = true,
|
||||||
|
on_stdout = function(_, data)
|
||||||
|
if data then
|
||||||
|
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, data)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
on_stderr = function(_, data)
|
||||||
|
if data then
|
||||||
|
vim.api.nvim_buf_set_lines(bufnr, -1, -1, false, data)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user