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::()); +}