Created
July 12, 2020 01:07
-
-
Save ManDeJan/bb0d6dbc98c65f257cc67bba5be01c0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const os = std.os; | |
pub fn main() void { | |
const filename = std.mem.span(os.argv[1]); | |
const open_result = os.open(filename, os.O_RDONLY, 0) catch unreachable; | |
const fstat_result = os.fstat(open_result) catch unreachable; | |
const data = os.mmap(null, @intCast(u64, fstat_result.size), os.PROT_READ, os.MAP_PRIVATE, open_result, 0) catch unreachable; | |
var count: i32 = 0; | |
var i: usize = 0; | |
while (i < fstat_result.size - 1) : (i += 6) { | |
var ints = [_]u8{0} ** 6; | |
var j: usize = 0; | |
while (j < 5) : (j += 1) { | |
ints[data[i + j] - '1'] += 1; | |
if (ints[data[i + j] - '1'] >= 3) { | |
count += 1; | |
break; | |
} | |
} | |
} | |
const stdout = std.io.getStdOut().outStream(); | |
stdout.print("{}", .{count}) catch unreachable; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment