Created
March 19, 2018 15:06
-
-
Save butlerx/1dd15797151d5bb8b34e00fdb835174d to your computer and use it in GitHub Desktop.
Multiples of 3 and 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn get_num() -> u64 { | |
let mut input = String::new(); | |
match std::io::stdin().read_line(&mut input) { | |
Ok(_n) => match input.trim().parse::<u64>() { | |
Ok(n) => n, | |
Err(_error) => 0, | |
}, | |
Err(_error) => 0, | |
} | |
} | |
fn main() { | |
for num in (0..get_num()) | |
.map(|_x| get_num()) | |
.collect::<Vec<u64>>() | |
.into_iter() | |
.map(|n| { | |
(3..n) | |
.filter(|&x| x % 3 == 0 || x % 5 == 0) | |
.fold(0, |sum, x| sum + x) | |
}) | |
.filter(|&x| x > 0) | |
{ | |
println!("{}", num); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment