finish 20

This commit is contained in:
Dr. Matthias Ratajczak
2022-08-19 16:07:56 +02:00
parent 6f8e78e112
commit 0b7e604056
2 changed files with 28 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
[package]
name = "euler20"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rust-gmp = "*"
+19
View File
@@ -0,0 +1,19 @@
use gmp::mpz::Mpz;
fn main() {
let x = faculty(Mpz::from(100));
let y: u32 = x
.to_string()
.chars()
.map(|c| c.to_digit(10).unwrap() as u32)
.sum();
println!("{y}");
}
fn faculty(x: Mpz) -> Mpz {
if x == Mpz::one() {
x
} else {
x.clone() * faculty(x - 1)
}
}