feat: solve day 11 puzzle 1

This commit is contained in:
2025-12-11 12:45:52 +01:00
parent 250be0f242
commit d0483124ac
5 changed files with 56 additions and 3 deletions

View File

@@ -8,10 +8,10 @@ This project can also be run using the amazing [CraftOS-PC emulator](https://git
## Progress
<!-- calendar-start -->
#### Stars: 18/24
#### Stars: 19/24
|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>:star::star:|6<br>:star::star:|7<br>:star::star:|
|8<br>:star::star:|9<br>:star:|10<br>:star:|11<br>|12<br>|||
|8<br>:star::star:|9<br>:star:|10<br>:star:|11<br>:star:|12<br>|||
<!-- calendar-end -->

10
res/examples/day11.txt Normal file
View File

@@ -0,0 +1,10 @@
aaa: you hhh
you: bbb ccc
bbb: ddd eee
ccc: ddd eee fff
ddd: ggg
eee: out
fff: out
ggg: out
hhh: ccc fff iii
iii: out

View File

@@ -40,7 +40,7 @@
"puzzle2": false
},
"day11": {
"puzzle1": false,
"puzzle1": true,
"puzzle2": false
},
"day12": {

36
src/day11/puzzle1.lua Normal file
View File

@@ -0,0 +1,36 @@
local strings = require "cc.strings"
local utils = require "utils"
local puzzle1 = {}
local cache = {}
function puzzle1.countPaths(edges, startDev, endDev)
local key = startDev .. "-" .. endDev
if cache[key] then
return cache[key]
end
if startDev == endDev then
return 1
end
local outs = edges[startDev]
local total = 0
for _, out in ipairs(outs) do
total = total + puzzle1.countPaths(edges, out, endDev)
end
cache[key] = total
return total
end
function puzzle1.solve(input)
local lines = utils.splitLines(input)
local outputs = {}
for _, line in ipairs(lines) do
local device, outs = line:match("(.+): (.+)")
outputs[device] = strings.split(outs, " ")
end
return puzzle1.countPaths(outputs, "you", "out")
end
return puzzle1

7
src/day11/puzzle2.lua Normal file
View File

@@ -0,0 +1,7 @@
local puzzle2 = {}
function puzzle2.solve(input)
return 0
end
return puzzle2