mirror of
https://codeberg.org/andyscott/exercism.git
synced 2024-11-09 13:20:48 -05:00
17 lines
381 B
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;
|
|
}
|