aboutsummaryrefslogtreecommitdiff
path: root/2020/day01
diff options
context:
space:
mode:
Diffstat (limited to '2020/day01')
-rw-r--r--2020/day01/src/main.rs17
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());
}