diff --git a/src/euler93/Cargo.toml b/src/euler93/Cargo.toml index d25de3e..69a13a5 100644 --- a/src/euler93/Cargo.toml +++ b/src/euler93/Cargo.toml @@ -6,3 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +itertools = "*" diff --git a/src/euler93/src/main.rs b/src/euler93/src/main.rs index 6c29e54..92359f8 100644 --- a/src/euler93/src/main.rs +++ b/src/euler93/src/main.rs @@ -1,3 +1,5 @@ +use itertools::Itertools; + type Num = f64; fn main() { @@ -18,21 +20,50 @@ fn main() { } } +fn recurse(array: &[Num]) -> Vec { + if array.len() == 2 { + let [a, b] = array else { panic!() }; + + let mut v = vec![]; + + for ops in Operations::iter() { + v.push(ops(*a, *b)); + } + v + } else { + let a = array[0]; + let b = array[1]; + + let mut v = vec![]; + + for ops in Operations::iter() { + v.push(ops(a, b)); + } + } +} + struct Digits(Num, Num, Num, Num); impl Digits { fn all_possible_integers(&self) -> Vec { - let a = self.0; - let b = self.1; - let c = self.2; - let d = self.3; + let array = [self.0, self.1, self.2, self.3]; - let outcomes: Vec<_> = Operations::new() - .map(|f| f(a, b) as u32) - .filter(|i| *i > 0) - .collect(); + array.into_iter().permutations(4).next().map(|a| { + for ops in Operations::iter() { + let x = ops(a[0], a[1]); + } + }); - dbg!(outcomes) + // dbg!(v); + + todo!() + + // let outcomes: Vec<_> = Operations::new() + // .map(|f| f(a, b) as u32) + // .filter(|i| *i > 0) + // .collect(); + + // dbg!(outcomes) } } @@ -58,7 +89,7 @@ impl Iterator for Operations { } impl Operations { - fn new() -> Self { + fn iter() -> Self { Self { last: 0 } } }