1diff --git a/src/day4.zig b/src/day4.zig
2new file mode 100644
3index 0000000000000000000000000000000000000000..878fa9180df8d93b0fcf6d2198b0b732d2017b04
4--- /dev/null
5+++ b/src/day4.zig
6@@ -0,0 +1,86 @@
7+const std = @import("std");
8+
9+pub fn pt1(input: []const u8) u64 {
10+ var counter: u64 = 0;
11+
12+ var lines = std.mem.splitScalar(u8, input, '\n');
13+
14+ var loop_count: usize = 0;
15+ while (lines.next()) |l| {
16+ if (l.len == 0) break;
17+ for (0..l.len) |y| {
18+ board[loop_count][y] = l[y] == '@';
19+ }
20+ loop_count += 1;
21+ }
22+
23+ for (0..board.len) |x| {
24+ for (0..board[x].len) |y| {
25+ if (board[x][y] and countSurround(x, y) < 4) {
26+ counter += 1;
27+ }
28+ }
29+ }
30+
31+ return counter;
32+}
33+
34+pub fn pt2(input: []const u8) u64 {
35+ var counter: u64 = 0;
36+
37+ var lines = std.mem.splitScalar(u8, input, '\n');
38+
39+ var loop_count: usize = 0;
40+ while (lines.next()) |l| {
41+ if (l.len == 0) break;
42+ for (0..l.len) |y| {
43+ board[loop_count][y] = l[y] == '@';
44+ }
45+ loop_count += 1;
46+ }
47+
48+ var hit = true;
49+ while (hit) {
50+ hit = false;
51+ for (0..board.len) |x| {
52+ for (0..board[x].len) |y| {
53+ if (board[x][y] and countSurround(x, y) < 4) {
54+ counter += 1;
55+ board[x][y] = false;
56+ hit = true;
57+ }
58+ }
59+ }
60+ }
61+
62+ return counter;
63+}
64+
65+var board: [138][138]bool = undefined;
66+fn countSurround(rx: usize, ry: usize) i64 {
67+ var count: i64 = 0;
68+
69+ const min_x = if (rx > 0) rx - 1 else 0;
70+ const max_x = if (rx + 1 < board.len) rx + 1 else board.len - 1;
71+ const min_y = if (ry > 0) ry - 1 else 0;
72+ const max_y = if (ry + 1 < board.len) ry + 1 else board.len - 1;
73+
74+ for (min_x..max_x + 1) |x| {
75+ for (min_y..max_y + 1) |y| {
76+ if (x == rx and y == ry) continue; // Skip the center cell
77+ if (board[x][y]) count += 1;
78+ }
79+ }
80+
81+ return count;
82+}
83+
84+test "Day 4 par 1" {
85+ const res = pt1(@embedFile("./input/day4"));
86+ try std.testing.expect(res == 1549);
87+}
88+
89+test "Day 4 par 2" {
90+ const res = pt2(@embedFile("./input/day4"));
91+ try std.testing.expect(res == 8887);
92+}
93diff --git a/src/input/day4 b/src/input/day4
94new file mode 100644
95index 0000000000000000000000000000000000000000..077dbbc3692bea9874c6efe168d843a119543f08
96Binary files /dev/null and b/src/input/day4 differ
97diff --git a/src/main.zig b/src/main.zig
98index 93f82e0a5b5b0ae9e893ad93f303fc42e4b68ca7..6455f59e76e1b787966c4f3dc6ec34b0870af721 100644
99--- a/src/main.zig
100+++ b/src/main.zig
101@@ -2,6 +2,7 @@ const std = @import("std");
102 const day1 = @import("day1.zig");
103 const day2 = @import("day2.zig");
104 const day3 = @import("day3.zig");
105+const day4 = @import("day4.zig");
106
107 pub export fn main() void {
108 for (1..std.os.argv.len) |i| {
109@@ -19,6 +20,10 @@ } else if (std.mem.eql(u8, "day3", day)) {
110 const input = @embedFile("./input/day3");
111 print(day3.pt1(input));
112 print(day3.pt2(input));
113+ } else if (std.mem.eql(u8, "day4", day)) {
114+ const input = @embedFile("./input/day4");
115+ print(day4.pt1(input));
116+ print(day4.pt2(input));
117 }
118 }
119 }