diff --git a/README.md b/README.md index 4d76adb..70878d6 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: 16/24 +#### Stars: 17/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
|10
|11
|12
||| +|8
:star::star:|9
:star:|10
|11
|12
||| diff --git a/res/examples/day09.txt b/res/examples/day09.txt new file mode 100644 index 0000000..7fb70de --- /dev/null +++ b/res/examples/day09.txt @@ -0,0 +1,8 @@ +7,1 +11,1 +11,7 +9,7 +9,5 +2,5 +2,3 +7,3 \ No newline at end of file diff --git a/res/stats.json b/res/stats.json index d79cd4d..6919d68 100644 --- a/res/stats.json +++ b/res/stats.json @@ -32,7 +32,7 @@ "puzzle2": true }, "day09": { - "puzzle1": false, + "puzzle1": true, "puzzle2": false }, "day10": { diff --git a/src/day09/puzzle1.lua b/src/day09/puzzle1.lua new file mode 100644 index 0000000..7114c3d --- /dev/null +++ b/src/day09/puzzle1.lua @@ -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 diff --git a/src/day09/puzzle2.lua b/src/day09/puzzle2.lua new file mode 100644 index 0000000..2f4bc9a --- /dev/null +++ b/src/day09/puzzle2.lua @@ -0,0 +1,7 @@ +local puzzle2 = {} + +function puzzle2.solve(input) + return 0 +end + +return puzzle2