Skip to content

Instantly share code, notes, and snippets.

@NickyMeuleman
Created June 25, 2021 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NickyMeuleman/872d8c7cb5c1fc74ceb547ce45e64961 to your computer and use it in GitHub Desktop.
Save NickyMeuleman/872d8c7cb5c1fc74ceb547ce45e64961 to your computer and use it in GitHub Desktop.
Check if a number is an Armstrong number
pub fn is_armstrong_number(num: u32) -> bool {
let digits: Vec<_> = num
.to_string()
.chars()
.filter_map(|n| n.to_digit(10))
.collect();
let num_digits = digits.len() as u32;
num == digits.iter().map(|n| n.pow(num_digits)).sum()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment