From 48fe778c503c688edc6972b3cd6071a0e901fd6f Mon Sep 17 00:00:00 2001 From: Muhammad Nauman Raza Date: Fri, 6 Dec 2024 09:04:54 +0000 Subject: [PATCH] solutions: 40 --- src/bin/champernownes_constant.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/bin/champernownes_constant.rs diff --git a/src/bin/champernownes_constant.rs b/src/bin/champernownes_constant.rs new file mode 100644 index 0000000..3b59ba5 --- /dev/null +++ b/src/bin/champernownes_constant.rs @@ -0,0 +1,16 @@ +fn main() { + let mut string: String = "0.".to_string(); + for i in 1..=185185 { + string.push_str(&i.to_string()); + } + + let digits = vec![1, 10, 100, 1000, 10_000, 100_000, 1_000_000]; + let mut multiplying: Vec = vec![]; + + for i in digits { + let digit = &string.chars().nth(i+1); + multiplying.push(digit.unwrap().to_digit(10).unwrap()); + } + + println!("{}", multiplying.iter().product::()); +}