Skip to content

Instantly share code, notes, and snippets.

@ManDeJan
Created July 12, 2020 01:07
Show Gist options
  • Save ManDeJan/bb0d6dbc98c65f257cc67bba5be01c0e to your computer and use it in GitHub Desktop.
Save ManDeJan/bb0d6dbc98c65f257cc67bba5be01c0e to your computer and use it in GitHub Desktop.
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