diff options
author | jacopograndi <jacopo.grandi@outlook.it> | 2022-03-24 22:00:15 +0100 |
---|---|---|
committer | jacopograndi <jacopo.grandi@outlook.it> | 2022-03-24 22:01:23 +0100 |
commit | c9cff7bc7723cb06807dee5c8e803fa8a0bba76f (patch) | |
tree | 639d0d58f123649c7442772555c5e4a51d2a7adf /2020/day01 | |
parent | 073cdf71d9fd45372f08112146b6349c6ba1c4d4 (diff) |
day01 both parts
Diffstat (limited to '2020/day01')
-rw-r--r-- | 2020/day01/src/main.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/2020/day01/src/main.rs b/2020/day01/src/main.rs index 02a3151..14a2d6d 100644 --- a/2020/day01/src/main.rs +++ b/2020/day01/src/main.rs @@ -19,4 +19,21 @@ fn main() { .collect(); println!("x+y = 2020, x*y = {}", res.first().unwrap()); + + let nx = nums.clone().into_iter(); + let ny = nums.clone().into_iter(); + let nz = nums.clone().into_iter(); + let cube = nx.flat_map(|x| { + ny.clone().flat_map({ + let nz = &nz; + move |y| nz.clone().map(move |z| (x, y, z)) + }) + }); + + let res : Vec<i32> = cube + .filter(|(x, y, z)| x+y+z == 2020) + .map(|(x, y, z)| x*y*z) + .collect(); + + println!("x+y+z = 2020, x*y*z = {}", res.first().unwrap()); } |