Bit late to the party, here is my iterator focused solution in rust. input is a Vec, aka the parsed input data
if let Some((a, b, c)) = input.iter().find_map(|a| { if let Some((b, c)) = input.iter().find_map(|b| { if let Some(c) = input.iter().find(|c| a + b + *c == 2020) { Some((b, c)) } else { None } }) { Some((a, b, c)) } else { None } }) { println!("A: {}, B: {}, C: {} result: {}", a, b, c, a * b * c); } else { println!("Could not find numbers fullfilling the requirement") }
Edit: solution 2, same concept, but more concise
match input.iter().find_map(|a| { input.iter().find_map(|b| { input.iter().find_map(|c| { if a + b + c == 2020 { Some((a, b, c)) } else { None } }) }) }) { Some((a, b, c)) => println!("A: {}, B: {}, C: {} result: {}", a, b, c, a * b * c), None => println!("Could not find numbers fullfilling the requirement"), }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Bit late to the party, here is my iterator focused solution in rust. input is a Vec, aka the parsed input data
Edit: solution 2, same concept, but more concise