From d9ac0c7a9f05b7ee23a8eda03c3095b65b4a832f Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Sat, 6 Dec 2025 11:36:03 +0100 Subject: [PATCH] feat: solve day 6 puzzle 1 --- README.md | 4 ++-- res/examples/day06.txt | 4 ++++ res/stats.json | 2 +- src/day06/puzzle1.lua | 39 +++++++++++++++++++++++++++++++++++++++ src/day06/puzzle2.lua | 7 +++++++ 5 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 res/examples/day06.txt create mode 100644 src/day06/puzzle1.lua create mode 100644 src/day06/puzzle2.lua diff --git a/README.md b/README.md index 50e8134..8083c96 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: 10/24 +#### Stars: 11/24 |Mon|Tue|Wed|Thu|Fri|Sat|Sun| |:-:|:-:|:-:|:-:|:-:|:-:|:-:| -|1
:star::star:|2
:star::star:|3
:star::star:|4
:star::star:|5
:star::star:|6
|7
| +|1
:star::star:|2
:star::star:|3
:star::star:|4
:star::star:|5
:star::star:|6
:star:|7
| |8
|9
|10
|11
|12
||| diff --git a/res/examples/day06.txt b/res/examples/day06.txt new file mode 100644 index 0000000..81c7af2 --- /dev/null +++ b/res/examples/day06.txt @@ -0,0 +1,4 @@ +123 328 51 64 + 45 64 387 23 + 6 98 215 314 +* + * + \ No newline at end of file diff --git a/res/stats.json b/res/stats.json index 0c99a6b..46ad079 100644 --- a/res/stats.json +++ b/res/stats.json @@ -20,7 +20,7 @@ "puzzle2": true }, "day06": { - "puzzle1": false, + "puzzle1": true, "puzzle2": false }, "day07": { diff --git a/src/day06/puzzle1.lua b/src/day06/puzzle1.lua new file mode 100644 index 0000000..3184fc9 --- /dev/null +++ b/src/day06/puzzle1.lua @@ -0,0 +1,39 @@ +local strings = require "cc.strings" +local puzzle1 = {} + +function puzzle1.solve(input) + local lines = strings.split(input, "\n") + local problems = {} + local n = #lines + + local ops = strings.split(lines[n], "%s+") + + for i, line in ipairs(lines) do + local j = 1 + for num in line:gmatch("(%d+)") do + local op = ops[j] + if i == 1 then + if op == "+" then + table.insert(problems, 0) + else + table.insert(problems, 1) + end + end + local val = tonumber(num) + if op == "+" then + problems[j] = problems[j] + val + else + problems[j] = problems[j] * val + end + j = j + 1 + end + end + + local total = 0 + for _, val in ipairs(problems) do + total = total + val + end + return total +end + +return puzzle1 diff --git a/src/day06/puzzle2.lua b/src/day06/puzzle2.lua new file mode 100644 index 0000000..2f4bc9a --- /dev/null +++ b/src/day06/puzzle2.lua @@ -0,0 +1,7 @@ +local puzzle2 = {} + +function puzzle2.solve(input) + return 0 +end + +return puzzle2