feat: solve day 5 puzzle 1
This commit is contained in:
@@ -8,10 +8,10 @@ This project can also be run using the amazing [CraftOS-PC emulator](https://git
|
|||||||
## Progress
|
## Progress
|
||||||
|
|
||||||
<!-- calendar-start -->
|
<!-- calendar-start -->
|
||||||
#### Stars: 8/24
|
#### Stars: 9/24
|
||||||
|
|
||||||
|Mon|Tue|Wed|Thu|Fri|Sat|Sun|
|
|Mon|Tue|Wed|Thu|Fri|Sat|Sun|
|
||||||
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
|
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
|
||||||
|1<br>:star::star:|2<br>:star::star:|3<br>:star::star:|4<br>:star::star:|5<br>|6<br>|7<br>|
|
|1<br>:star::star:|2<br>:star::star:|3<br>:star::star:|4<br>:star::star:|5<br>:star:|6<br>|7<br>|
|
||||||
|8<br>|9<br>|10<br>|11<br>|12<br>|||
|
|8<br>|9<br>|10<br>|11<br>|12<br>|||
|
||||||
<!-- calendar-end -->
|
<!-- calendar-end -->
|
||||||
|
|||||||
11
res/examples/day05.txt
Normal file
11
res/examples/day05.txt
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
3-5
|
||||||
|
10-14
|
||||||
|
16-20
|
||||||
|
12-18
|
||||||
|
|
||||||
|
1
|
||||||
|
5
|
||||||
|
8
|
||||||
|
11
|
||||||
|
17
|
||||||
|
32
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
"puzzle2": true
|
"puzzle2": true
|
||||||
},
|
},
|
||||||
"day05": {
|
"day05": {
|
||||||
"puzzle1": false,
|
"puzzle1": true,
|
||||||
"puzzle2": false
|
"puzzle2": false
|
||||||
},
|
},
|
||||||
"day06": {
|
"day06": {
|
||||||
|
|||||||
39
src/day05/puzzle1.lua
Normal file
39
src/day05/puzzle1.lua
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
local strings = require "cc.strings"
|
||||||
|
local puzzle1 = {}
|
||||||
|
|
||||||
|
function puzzle1.isFresh(ranges, i)
|
||||||
|
for _, range in ipairs(ranges) do
|
||||||
|
if range[1] <= i and i <= range[2] then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
function puzzle1.solve(input)
|
||||||
|
local lines = strings.split(input, "\n")
|
||||||
|
local ranges = {}
|
||||||
|
|
||||||
|
local bIngr = false
|
||||||
|
local totalFresh = 0
|
||||||
|
|
||||||
|
for _, line in ipairs(lines) do
|
||||||
|
if line == "" then
|
||||||
|
bIngr = true
|
||||||
|
else
|
||||||
|
if bIngr then
|
||||||
|
local ingr = tonumber(line)
|
||||||
|
if puzzle1.isFresh(ranges, ingr) then
|
||||||
|
totalFresh = totalFresh + 1
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local min, max = line:match("(%d+)%-(%d+)")
|
||||||
|
table.insert(ranges, {tonumber(min), tonumber(max)})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return totalFresh
|
||||||
|
end
|
||||||
|
|
||||||
|
return puzzle1
|
||||||
7
src/day05/puzzle2.lua
Normal file
7
src/day05/puzzle2.lua
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
local puzzle2 = {}
|
||||||
|
|
||||||
|
function puzzle2.solve(input)
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
return puzzle2
|
||||||
Reference in New Issue
Block a user