solutions: 20
This commit is contained in:
parent
f0858b63e6
commit
e058da0bd4
1 changed files with 19 additions and 0 deletions
19
src/bin/factorial_digit_sum.rs
Normal file
19
src/bin/factorial_digit_sum.rs
Normal file
|
@ -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<u64> = vec![];
|
||||
for i in number.to_string().chars().filter_map(|c| c.to_digit(10)) {
|
||||
digits.push(i as u64);
|
||||
}
|
||||
|
||||
println!("{}", digits.iter().sum::<u64>());
|
||||
}
|
Loading…
Reference in a new issue