From 472634054f24edb7161ae94bc2869f7117eed196 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Sun, 7 Dec 2025 13:44:31 +0100 Subject: [PATCH] feat: solve day 7 puzzle 2 --- README.md | 4 ++-- res/stats.json | 2 +- src/day07/puzzle2.lua | 32 +++++++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6189714..4937af2 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: 13/24 +#### Stars: 14/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
:star:| +|1
:star::star:|2
:star::star:|3
:star::star:|4
:star::star:|5
:star::star:|6
:star::star:|7
:star::star:| |8
|9
|10
|11
|12
||| diff --git a/res/stats.json b/res/stats.json index ed7de2d..1191135 100644 --- a/res/stats.json +++ b/res/stats.json @@ -25,7 +25,7 @@ }, "day07": { "puzzle1": true, - "puzzle2": false + "puzzle2": true }, "day08": { "puzzle1": false, diff --git a/src/day07/puzzle2.lua b/src/day07/puzzle2.lua index 2f4bc9a..e8e0482 100644 --- a/src/day07/puzzle2.lua +++ b/src/day07/puzzle2.lua @@ -1,7 +1,37 @@ +local utils = require "utils" + local puzzle2 = {} function puzzle2.solve(input) - return 0 + local lines = utils.splitLines(input) + + local beams = {} + + for i, line in ipairs(lines) do + local newBeams = {} + if i == 1 then + newBeams[line:find("S")] = 1 + else + for j=1, #line do + if beams[j] then + if line:sub(j, j) == "^" then + newBeams[j - 1] = (newBeams[j - 1] or 0) + beams[j] + newBeams[j + 1] = (newBeams[j + 1] or 0) + beams[j] + else + newBeams[j] = (newBeams[j] or 0) + beams[j] + end + end + end + end + beams = newBeams + end + + local finalBeams = 0 + for _, v in pairs(beams) do + finalBeams = finalBeams + v + end + + return finalBeams end return puzzle2