armstrong numbers

This commit is contained in:
Rorik Star Platinum 2025-12-08 21:57:48 +03:00
parent edb9158b39
commit fb03ef20e4
7 changed files with 240 additions and 0 deletions

View file

@ -0,0 +1,12 @@
pub fn is_armstrong_number(num: u32) -> bool {
if 0 == num {
return true;
}
let count = (num as f64).log10().floor() as u32 + 1;
let sum: u32 = (1..=count)
.map(|i| num % 10_u32.pow(i) / 10_u32.pow(i - 1))
.map(|x| (x).pow(count))
.sum();
sum == num
}