exercism/zig/armstrong-numbers/armstrong_numbers.zig

17 lines
381 B
Zig

const std = @import("std");
pub fn isArmstrongNumber(num: u128) bool {
var digits: u8 = 0;
var digits_rem = num;
while (digits_rem != 0) : (digits_rem /= 10) {
digits += 1;
}
var sum: u128 = 0;
var num_rem = num;
while (num_rem != 0) : (num_rem /= 10) {
sum += std.math.pow(u128, num_rem % 10, digits);
}
return num == sum;
}