diff --git a/src/bin/factorial_digit_sum.rs b/src/bin/factorial_digit_sum.rs new file mode 100644 index 0000000..a21f52c --- /dev/null +++ b/src/bin/factorial_digit_sum.rs @@ -0,0 +1,19 @@ +use num_bigint::BigUint; + +fn factorial(x: u64) -> BigUint { + let mut product = BigUint::from(1 as u64); + for i in 2..=x { + product *= BigUint::from(i); + } + product.into() +} + +fn main() { + let number = factorial(100); + let mut digits: Vec = vec![]; + for i in number.to_string().chars().filter_map(|c| c.to_digit(10)) { + digits.push(i as u64); + } + + println!("{}", digits.iter().sum::()); +}