feat: solve day 9 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: 16/24
|
#### Stars: 17/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>:star::star:|
|
|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>|10<br>|11<br>|12<br>|||
|
|8<br>:star::star:|9<br>:star:|10<br>|11<br>|12<br>|||
|
||||||
<!-- calendar-end -->
|
<!-- calendar-end -->
|
||||||
|
|||||||
8
res/examples/day09.txt
Normal file
8
res/examples/day09.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
7,1
|
||||||
|
11,1
|
||||||
|
11,7
|
||||||
|
9,7
|
||||||
|
9,5
|
||||||
|
2,5
|
||||||
|
2,3
|
||||||
|
7,3
|
||||||
@@ -32,7 +32,7 @@
|
|||||||
"puzzle2": true
|
"puzzle2": true
|
||||||
},
|
},
|
||||||
"day09": {
|
"day09": {
|
||||||
"puzzle1": false,
|
"puzzle1": true,
|
||||||
"puzzle2": false
|
"puzzle2": false
|
||||||
},
|
},
|
||||||
"day10": {
|
"day10": {
|
||||||
|
|||||||
30
src/day09/puzzle1.lua
Normal file
30
src/day09/puzzle1.lua
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
local utils = require "utils"
|
||||||
|
local puzzle1 = {}
|
||||||
|
|
||||||
|
function puzzle1.area(tile1, tile2)
|
||||||
|
local dx = math.abs(tile2.x - tile1.x) + 1
|
||||||
|
local dy = math.abs(tile2.y - tile1.y) + 1
|
||||||
|
return dx * dy
|
||||||
|
end
|
||||||
|
|
||||||
|
function puzzle1.solve(input)
|
||||||
|
local lines = utils.splitLines(input)
|
||||||
|
local tiles = {}
|
||||||
|
|
||||||
|
for _, line in ipairs(lines) do
|
||||||
|
local x, y = line:match("(%d+),(%d+)")
|
||||||
|
table.insert(tiles, {x=tonumber(x), y=tonumber(y)})
|
||||||
|
end
|
||||||
|
|
||||||
|
local maxArea = 0
|
||||||
|
for i, tile1 in ipairs(tiles) do
|
||||||
|
for j=i+1, #tiles do
|
||||||
|
local tile2 = tiles[j]
|
||||||
|
local area = puzzle1.area(tile1, tile2)
|
||||||
|
maxArea = math.max(maxArea, area)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return maxArea
|
||||||
|
end
|
||||||
|
|
||||||
|
return puzzle1
|
||||||
7
src/day09/puzzle2.lua
Normal file
7
src/day09/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