feat: solve day 7 puzzle 1
This commit is contained in:
@@ -8,10 +8,10 @@ This project can also be run using the amazing [CraftOS-PC emulator](https://git
|
|||||||
## Progress
|
## Progress
|
||||||
|
|
||||||
<!-- calendar-start -->
|
<!-- calendar-start -->
|
||||||
#### Stars: 12/24
|
#### Stars: 13/24
|
||||||
|
|
||||||
|Mon|Tue|Wed|Thu|Fri|Sat|Sun|
|
|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>|
|
|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:|
|
||||||
|8<br>|9<br>|10<br>|11<br>|12<br>|||
|
|8<br>|9<br>|10<br>|11<br>|12<br>|||
|
||||||
<!-- calendar-end -->
|
<!-- calendar-end -->
|
||||||
|
|||||||
16
res/examples/day07.txt
Normal file
16
res/examples/day07.txt
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
.......S.......
|
||||||
|
...............
|
||||||
|
.......^.......
|
||||||
|
...............
|
||||||
|
......^.^......
|
||||||
|
...............
|
||||||
|
.....^.^.^.....
|
||||||
|
...............
|
||||||
|
....^.^...^....
|
||||||
|
...............
|
||||||
|
...^.^...^.^...
|
||||||
|
...............
|
||||||
|
..^...^.....^..
|
||||||
|
...............
|
||||||
|
.^.^.^.^.^...^.
|
||||||
|
...............
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
"puzzle2": true
|
"puzzle2": true
|
||||||
},
|
},
|
||||||
"day07": {
|
"day07": {
|
||||||
"puzzle1": false,
|
"puzzle1": true,
|
||||||
"puzzle2": false
|
"puzzle2": false
|
||||||
},
|
},
|
||||||
"day08": {
|
"day08": {
|
||||||
|
|||||||
34
src/day07/puzzle1.lua
Normal file
34
src/day07/puzzle1.lua
Normal file
@@ -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
|
||||||
7
src/day07/puzzle2.lua
Normal file
7
src/day07/puzzle2.lua
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
local puzzle2 = {}
|
||||||
|
|
||||||
|
function puzzle2.solve(input)
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
return puzzle2
|
||||||
Reference in New Issue
Block a user