about summary refs log tree commit diff
path: root/aoc/2021/09/part-one.zig
diff options
context:
space:
mode:
Diffstat (limited to 'aoc/2021/09/part-one.zig')
-rw-r--r--aoc/2021/09/part-one.zig33
1 files changed, 33 insertions, 0 deletions
diff --git a/aoc/2021/09/part-one.zig b/aoc/2021/09/part-one.zig
new file mode 100644
index 0000000..8e3ae15
--- /dev/null
+++ b/aoc/2021/09/part-one.zig
@@ -0,0 +1,33 @@
+const print = std.debug.print;
+const std = @import("std");
+
+const input = @embedFile("input");
+
+inline fn get(x: i8, y: i8) u8 {
+    return switch (x) {
+        0...99 => switch (y) {
+            0...99 => input[@intCast(usize, x) + @intCast(usize, y) * 101],
+            else => ':',
+        },
+        else => ':',
+    };
+}
+
+pub fn main() void {
+    var sum: usize = 0;
+    defer print("{}\n", .{ sum });
+
+    var row: i8 = 0;
+    while (row < 100) : (row += 1) {
+        var col: i8 = 0;
+        while (col < 100) : (col += 1) {
+            const height = get(col, row);
+            sum += @boolToInt(@reduce(.And, @Vector(4, u8){
+                get(col + 1, row),
+                get(col, row + 1),
+                get(col - 1, row),
+                get(col, row - 1),
+            } > @splat(4, height))) * (height - '/');
+        }
+    }
+}