Skip to content

Instantly share code, notes, and snippets.

@butlerx
Created March 19, 2018 15:06
Show Gist options
  • Save butlerx/1dd15797151d5bb8b34e00fdb835174d to your computer and use it in GitHub Desktop.
Save butlerx/1dd15797151d5bb8b34e00fdb835174d to your computer and use it in GitHub Desktop.
Multiples of 3 and 5
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