From c9cff7bc7723cb06807dee5c8e803fa8a0bba76f Mon Sep 17 00:00:00 2001 From: jacopograndi Date: Thu, 24 Mar 2022 22:00:15 +0100 Subject: day01 both parts --- 2020/day01/src/main.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to '2020') 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 = 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()); } -- cgit v1.2.3-54-g00ecf