const std = @import("std"); const path = "data/day08/input.txt"; const RetType = u9; pub fn parseInput() anyerror!RetType { const input = @embedFile(path); var lines = std.mem.tokenize(u8, input, "\n"); var counter: RetType = 0; while (lines.next()) |line| { var pattern_output = std.mem.tokenize(u8, line, "|"); _ = pattern_output.next(); // just skip patterns var outs = std.mem.tokenize(u8, pattern_output.next().?, " "); while (outs.next()) |out| { if ((out.len == 2) or (out.len == 4) or (out.len == 3) or (out.len == 7)) { counter += 1; } } } return counter; } pub fn first(allocator: ?std.mem.Allocator) anyerror!RetType { _ = allocator; return try parseInput(); } pub fn main() anyerror!void { var timer = try std.time.Timer.start(); const ret = try first(null); const f = timer.lap() / 1000; try std.testing.expectEqual(ret, @as(RetType, 381)); std.debug.print("Day 8a result: {d} \t\ttime: {d}us\n", .{ ret, f }); } test "day08a" { try std.testing.expectEqual(@as(RetType, 381), try first(std.testing.allocator)); }