14 lines
397 B
Rust
14 lines
397 B
Rust
|
pub fn is_armstrong_number(num: u32) -> bool {
|
||
|
let Some(count) = num.checked_ilog10().map(|count| count + 1) else {
|
||
|
return true;
|
||
|
};
|
||
|
let armstrong_sum = (0..count).map(|i| {
|
||
|
let divisor = 10u32.pow(i);
|
||
|
let quotient = num / divisor;
|
||
|
let digit = quotient % 10;
|
||
|
let raised = digit.pow(count);
|
||
|
raised
|
||
|
}).sum();
|
||
|
num == armstrong_sum
|
||
|
}
|