exercism/zig/scrabble-score/scrabble_score.zig

18 lines
474 B
Zig

const std = @import("std");
pub fn score(s: []const u8) u32 {
var total: u32 = 0;
for (s) |c| {
total += switch (std.ascii.toLower(c)) {
'a', 'e', 'i', 'o', 'u', 'l', 'n', 'r', 's', 't' => 1,
'd', 'g' => 2,
'b', 'c', 'm', 'p' => 3,
'f', 'h', 'v', 'w', 'y' => 4,
'k' => 5,
'j', 'x' => 8,
'q', 'z' => 10,
else => unreachable,
};
}
return total;
}