but I would like to be able to count the following tuples twice since both values satisfy the condition
(6, 15)
(12, 9)
(18, 3)
and end up with a count of 16. Any suggestions for how to accomplish this? I'm trying to avoid iterating separately and then adding the counts together.
But then why are you filtering in this case at all? It completely defeats the purpose of using the "score". You could just assign a score of 0 when neither condition is satisfied, and you don't need the if-else either:
let count = (1..=20).zip((1..=20).rev())
.map(|(a, b)| (a % 2 == 0) as usize + (b % 3 == 0) as usize)
.sum::<usize>();
println!("{}", count); // 16
You are right of course. I didn't put much thought into it after realizing I had put out an XY problem. The example code was not really indicative of the problem I was actually trying to solve, just of the flawed method I was trying to use to solve it.