feat: solve day 6 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: 10/24
|
#### Stars: 11/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>|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:|7<br>|
|
||||||
|8<br>|9<br>|10<br>|11<br>|12<br>|||
|
|8<br>|9<br>|10<br>|11<br>|12<br>|||
|
||||||
<!-- calendar-end -->
|
<!-- calendar-end -->
|
||||||
|
|||||||
4
res/examples/day06.txt
Normal file
4
res/examples/day06.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
123 328 51 64
|
||||||
|
45 64 387 23
|
||||||
|
6 98 215 314
|
||||||
|
* + * +
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
"puzzle2": true
|
"puzzle2": true
|
||||||
},
|
},
|
||||||
"day06": {
|
"day06": {
|
||||||
"puzzle1": false,
|
"puzzle1": true,
|
||||||
"puzzle2": false
|
"puzzle2": false
|
||||||
},
|
},
|
||||||
"day07": {
|
"day07": {
|
||||||
|
|||||||
39
src/day06/puzzle1.lua
Normal file
39
src/day06/puzzle1.lua
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
local strings = require "cc.strings"
|
||||||
|
local puzzle1 = {}
|
||||||
|
|
||||||
|
function puzzle1.solve(input)
|
||||||
|
local lines = strings.split(input, "\n")
|
||||||
|
local problems = {}
|
||||||
|
local n = #lines
|
||||||
|
|
||||||
|
local ops = strings.split(lines[n], "%s+")
|
||||||
|
|
||||||
|
for i, line in ipairs(lines) do
|
||||||
|
local j = 1
|
||||||
|
for num in line:gmatch("(%d+)") do
|
||||||
|
local op = ops[j]
|
||||||
|
if i == 1 then
|
||||||
|
if op == "+" then
|
||||||
|
table.insert(problems, 0)
|
||||||
|
else
|
||||||
|
table.insert(problems, 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local val = tonumber(num)
|
||||||
|
if op == "+" then
|
||||||
|
problems[j] = problems[j] + val
|
||||||
|
else
|
||||||
|
problems[j] = problems[j] * val
|
||||||
|
end
|
||||||
|
j = j + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local total = 0
|
||||||
|
for _, val in ipairs(problems) do
|
||||||
|
total = total + val
|
||||||
|
end
|
||||||
|
return total
|
||||||
|
end
|
||||||
|
|
||||||
|
return puzzle1
|
||||||
7
src/day06/puzzle2.lua
Normal file
7
src/day06/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