M Cargo.lock => Cargo.lock +7 -0
@@ 45,6 45,13 @@ dependencies = [
]
[[package]]
+name = "problem_008"
+version = "0.1.0"
+dependencies = [
+ "common 0.1.0",
+]
+
+[[package]]
name = "problem_009"
version = "0.1.0"
dependencies = [
M Cargo.toml => Cargo.toml +1 -0
@@ 7,6 7,7 @@ members = [
"problem_005",
"problem_006",
"problem_007",
+ "problem_008",
"problem_009",
"problem_010",
"problem_019",
A problem_008/Cargo.toml => problem_008/Cargo.toml +8 -0
@@ 0,0 1,8 @@
+[package]
+name = "problem_008"
+version = "0.1.0"
+authors = ["Jan Baudisch <dev@baudisch.xyz>"]
+edition = "2018"
+
+[dependencies]
+common = { path = "../common" }
A problem_008/src/main.rs => problem_008/src/main.rs +31 -0
@@ 0,0 1,31 @@
+use common::input;
+
+fn main() {
+ println!("[INPUT] number (multi-line):");
+ let input: Vec<String> = input::read_lines();
+ let digits = input
+ .iter()
+ .fold(String::new(), |string, part| string + part)
+ .chars()
+ .map(|digit| digit.to_digit(10).expect("Could not parse input!"))
+ .collect::<Vec<u32>>();
+
+ let mut largest = 0;
+
+ for start in 0..digits.len() - 12 {
+ let mut product = 1;
+
+ for i in 0..13 {
+ product *= u64::from(digits[start + i]);
+ }
+
+ if product > largest {
+ largest = product;
+ }
+ }
+
+ println!(
+ "[SOLUTION] largest product of 13 adjacent digits: {}",
+ largest
+ );
+}