From 39c03d992024886641e98deb1b94806b79ce4a73 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Sun, 7 Dec 2025 13:37:38 +0100 Subject: [PATCH] feat: solve day 7 puzzle 1 --- README.md | 4 ++-- res/examples/day07.txt | 16 ++++++++++++++++ res/stats.json | 2 +- src/day07/puzzle1.lua | 34 ++++++++++++++++++++++++++++++++++ src/day07/puzzle2.lua | 7 +++++++ 5 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 res/examples/day07.txt create mode 100644 src/day07/puzzle1.lua create mode 100644 src/day07/puzzle2.lua diff --git a/README.md b/README.md index 59cf567..6189714 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: 12/24 +#### Stars: 13/24 |Mon|Tue|Wed|Thu|Fri|Sat|Sun| |:-:|:-:|:-:|:-:|:-:|:-:|:-:| -|1
:star::star:|2
:star::star:|3
:star::star:|4
:star::star:|5
:star::star:|6
:star::star:|7
| +|1
:star::star:|2
:star::star:|3
:star::star:|4
:star::star:|5
:star::star:|6
:star::star:|7
:star:| |8
|9
|10
|11
|12
||| diff --git a/res/examples/day07.txt b/res/examples/day07.txt new file mode 100644 index 0000000..8868910 --- /dev/null +++ b/res/examples/day07.txt @@ -0,0 +1,16 @@ +.......S....... +............... +.......^....... +............... +......^.^...... +............... +.....^.^.^..... +............... +....^.^...^.... +............... +...^.^...^.^... +............... +..^...^.....^.. +............... +.^.^.^.^.^...^. +............... \ No newline at end of file diff --git a/res/stats.json b/res/stats.json index 73b3cfe..ed7de2d 100644 --- a/res/stats.json +++ b/res/stats.json @@ -24,7 +24,7 @@ "puzzle2": true }, "day07": { - "puzzle1": false, + "puzzle1": true, "puzzle2": false }, "day08": { diff --git a/src/day07/puzzle1.lua b/src/day07/puzzle1.lua new file mode 100644 index 0000000..5586f13 --- /dev/null +++ b/src/day07/puzzle1.lua @@ -0,0 +1,34 @@ +local utils = require "utils" + +local puzzle1 = {} + +function puzzle1.solve(input) + local lines = utils.splitLines(input) + + local beams = {} + local totalSplits = 0 + + for i, line in ipairs(lines) do + local newBeams = {} + if i == 1 then + newBeams[line:find("S")] = true + else + for j=1, #line do + if beams[j] then + if line:sub(j, j) == "^" then + totalSplits = totalSplits + 1 + newBeams[j - 1] = true + newBeams[j + 1] = true + else + newBeams[j] = true + end + end + end + end + beams = newBeams + end + + return totalSplits +end + +return puzzle1 diff --git a/src/day07/puzzle2.lua b/src/day07/puzzle2.lua new file mode 100644 index 0000000..2f4bc9a --- /dev/null +++ b/src/day07/puzzle2.lua @@ -0,0 +1,7 @@ +local puzzle2 = {} + +function puzzle2.solve(input) + return 0 +end + +return puzzle2