mirror of
https://codeberg.org/andyscott/exercism.git
synced 2024-12-22 14:43:10 -05:00
18 lines
381 B
Zig
18 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;
|
||
|
}
|