diff --git a/README.md b/README.md
index 2735622..b46c5f7 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: 19/24
+#### Stars: 20/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::star:|
-|8
:star::star:|9
:star:|10
:star:|11
:star:|12
|||
+|8
:star::star:|9
:star:|10
:star:|11
:star::star:|12
|||
diff --git a/res/examples/day11.txt b/res/examples/day11.txt
index 8dc75a3..2bd407b 100644
--- a/res/examples/day11.txt
+++ b/res/examples/day11.txt
@@ -1,10 +1,13 @@
-aaa: you hhh
-you: bbb ccc
-bbb: ddd eee
-ccc: ddd eee fff
-ddd: ggg
-eee: out
-fff: out
+svr: aaa bbb
+aaa: fft
+fft: ccc
+bbb: tty
+tty: ccc
+ccc: ddd eee
+ddd: hub
+hub: fff
+eee: dac
+dac: fff
+fff: ggg hhh
ggg: out
-hhh: ccc fff iii
-iii: out
\ No newline at end of file
+hhh: out
\ No newline at end of file
diff --git a/res/examples/day11_1.txt b/res/examples/day11_1.txt
new file mode 100644
index 0000000..8dc75a3
--- /dev/null
+++ b/res/examples/day11_1.txt
@@ -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
\ No newline at end of file
diff --git a/res/stats.json b/res/stats.json
index f96fefa..262ca82 100644
--- a/res/stats.json
+++ b/res/stats.json
@@ -41,7 +41,7 @@
},
"day11": {
"puzzle1": true,
- "puzzle2": false
+ "puzzle2": true
},
"day12": {
"puzzle1": false,
diff --git a/src/day11/puzzle2.lua b/src/day11/puzzle2.lua
index 2f4bc9a..b2ced6e 100644
--- a/src/day11/puzzle2.lua
+++ b/src/day11/puzzle2.lua
@@ -1,7 +1,49 @@
+local strings = require "cc.strings"
+local utils = require "utils"
local puzzle2 = {}
+local cache = {}
+
+function puzzle2.countPaths(edges, startDev, endDev, dac, fft)
+ dac = dac or false
+ fft = fft or false
+ local key = startDev .. "-" .. endDev .. "-" .. tostring(dac) .. "-" .. tostring(fft)
+ if cache[key] then
+ return cache[key]
+ end
+ if startDev == endDev then
+ if dac and fft then
+ return 1
+ else
+ return 0
+ end
+ end
+ local outs = edges[startDev]
+ local total = 0
+ for _, out in ipairs(outs) do
+ local dac2 = dac
+ local fft2 = fft
+ if out == "dac" then
+ dac2 = true
+ elseif out == "fft" then
+ fft2 = true
+ end
+ total = total + puzzle2.countPaths(edges, out, endDev, dac2, fft2)
+ end
+ cache[key] = total
+ return total
+end
+
function puzzle2.solve(input)
- return 0
+ 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 puzzle2.countPaths(outputs, "svr", "out")
end
return puzzle2