mirror of
https://codeberg.org/andyscott/exercism.git
synced 2024-11-14 07:10:48 -05:00
26 lines
548 B
Zig
26 lines
548 B
Zig
pub const std = @import("std");
|
|
|
|
pub fn cmp(context: void, a: u8, b: u8) bool {
|
|
_ = context;
|
|
if (a < b) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
pub fn isIsogram(str: []const u8) bool {
|
|
const len = str.len;
|
|
if (len == 0) return true;
|
|
|
|
var buf = [_]u8{0} ** 256;
|
|
const lower = std.ascii.lowerString(&buf, str);
|
|
std.mem.sort(u8, lower, {}, cmp);
|
|
|
|
for (0..len - 1) |i| {
|
|
if (lower[i] == lower[i + 1] and std.ascii.isAlphabetic(lower[i])) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|