Day5 First puzzle get
This commit is contained in:
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
|
||||||
Reference in New Issue
Block a user