diff --git a/README.md b/README.md index 2ff4f39..ea29d06 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,10 @@ This project can also be run using the amazing [CraftOS-PC emulator](https://git ## Progress -#### Stars: 8/24 +#### Stars: 9/24 |Mon|Tue|Wed|Thu|Fri|Sat|Sun| |:-:|:-:|:-:|:-:|:-:|:-:|:-:| -|1
:star::star:|2
:star::star:|3
:star::star:|4
:star::star:|5
|6
|7
| +|1
:star::star:|2
:star::star:|3
:star::star:|4
:star::star:|5
:star:|6
|7
| |8
|9
|10
|11
|12
||| diff --git a/res/examples/day05.txt b/res/examples/day05.txt new file mode 100644 index 0000000..ca4fb6b --- /dev/null +++ b/res/examples/day05.txt @@ -0,0 +1,11 @@ +3-5 +10-14 +16-20 +12-18 + +1 +5 +8 +11 +17 +32 \ No newline at end of file diff --git a/res/stats.json b/res/stats.json index 21a0983..4c24ab6 100644 --- a/res/stats.json +++ b/res/stats.json @@ -16,7 +16,7 @@ "puzzle2": true }, "day05": { - "puzzle1": false, + "puzzle1": true, "puzzle2": false }, "day06": { diff --git a/src/day05/puzzle1.lua b/src/day05/puzzle1.lua new file mode 100644 index 0000000..5583413 --- /dev/null +++ b/src/day05/puzzle1.lua @@ -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 diff --git a/src/day05/puzzle2.lua b/src/day05/puzzle2.lua new file mode 100644 index 0000000..2f4bc9a --- /dev/null +++ b/src/day05/puzzle2.lua @@ -0,0 +1,7 @@ +local puzzle2 = {} + +function puzzle2.solve(input) + return 0 +end + +return puzzle2