-- 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)