diff --git a/README.md b/README.md
index 60cc3f9..db17411 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: 6/24
+#### Stars: 7/24
|Mon|Tue|Wed|Thu|Fri|Sat|Sun|
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
-|1
:star::star:|2
:star::star:|3
:star::star:|4
|5
|6
|7
|
+|1
:star::star:|2
:star::star:|3
:star::star:|4
:star:|5
|6
|7
|
|8
|9
|10
|11
|12
|||
diff --git a/res/examples/day04.txt b/res/examples/day04.txt
new file mode 100644
index 0000000..9ad769d
--- /dev/null
+++ b/res/examples/day04.txt
@@ -0,0 +1,10 @@
+..@@.@@@@.
+@@@.@.@.@@
+@@@@@.@.@@
+@.@@@@..@.
+@@.@@@@.@@
+.@@@@@@@.@
+.@.@.@.@@@
+@.@@@.@@@@
+.@@@@@@@@.
+@.@.@@@.@.
\ No newline at end of file
diff --git a/res/stats.json b/res/stats.json
index 359a654..1b76e81 100644
--- a/res/stats.json
+++ b/res/stats.json
@@ -12,7 +12,7 @@
"puzzle2": true
},
"day04": {
- "puzzle1": false,
+ "puzzle1": true,
"puzzle2": false
},
"day05": {
diff --git a/src/day04/puzzle1.lua b/src/day04/puzzle1.lua
new file mode 100644
index 0000000..7ba3ece
--- /dev/null
+++ b/src/day04/puzzle1.lua
@@ -0,0 +1,44 @@
+local utils = require "utils"
+
+local puzzle1 = {}
+
+function puzzle1.inGrid(x, y, w, h)
+ return 1 <= x and x <= w and 1 <= y and y <= h
+end
+
+function puzzle1.isAccessible(lines, w, h, x, y)
+ local neighbors = 0
+ for dy=-1, 1 do
+ for dx=-1, 1 do
+ if dx ~=0 or dy ~= 0 then
+ local x2 = x + dx
+ local y2 = y + dy
+ if puzzle1.inGrid(x2, y2, w, h) then
+ if lines[y2]:sub(x2, x2) == "@" then
+ neighbors = neighbors + 1
+ end
+ end
+ end
+ end
+ end
+ return neighbors < 4
+end
+
+function puzzle1.solve(input)
+ local lines = utils.splitLines(input)
+ local accessible = 0
+
+ local h = #lines
+ local w = #lines[1]
+
+ for y, line in ipairs(lines) do
+ for x=1, #line do
+ if line:sub(x, x) == "@" and puzzle1.isAccessible(lines, w, h, x, y) then
+ accessible = accessible + 1
+ end
+ end
+ end
+ return accessible
+end
+
+return puzzle1
diff --git a/src/day04/puzzle2.lua b/src/day04/puzzle2.lua
new file mode 100644
index 0000000..2f4bc9a
--- /dev/null
+++ b/src/day04/puzzle2.lua
@@ -0,0 +1,7 @@
+local puzzle2 = {}
+
+function puzzle2.solve(input)
+ return 0
+end
+
+return puzzle2