exercism/zig/hamming/hamming.zig

15 lines
409 B
Zig

pub const DnaError = error{
EmptyDnaStrands,
UnequalDnaStrands,
};
pub fn compute(first: []const u8, second: []const u8) DnaError!usize {
if (first.len == 0 or second.len == 0) return DnaError.EmptyDnaStrands;
if (first.len != second.len) return DnaError.UnequalDnaStrands;
var count: usize = 0;
for (first, second) |i, j| {
if (i != j) count += 1;
}
return count;
}