const std = @import("std");

const PATH = "input/day01.txt";

pub fn first(allocator: ?std.mem.Allocator) !isize {
    _ = allocator;

    const input = @embedFile(PATH);

    var ret: isize = 0;
    for (input) |ch| {
        switch (ch) {
            '(' => ret += 1,
            ')' => ret -= 1,
            else => {},
        }
    }

    return ret;
}

pub fn second(allocator: ?std.mem.Allocator) !usize {
    _ = allocator;

    const input = @embedFile(PATH);

    var floor: usize = 0;
    for (input) |ch, idx| {
        switch (ch) {
            '(' => floor += 1,
            ')' => {
                if (floor == 0) return idx + 1;
                floor -= 1;
            },
            else => unreachable,
        }
    }

    unreachable;
}

test "day01a" {
    try std.testing.expectEqual(@as(isize, 74), try first(std.testing.allocator));
}

test "day01b" {
    try std.testing.expectEqual(@as(usize, 1795), try second(std.testing.allocator));
}