solutions to project euler problems in rust
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
505 B

// Problem 1:
// If we list all the natural numbers below 10 that are multiples of 3 or 5, we
// get 3, 5, 6 and 9. The sum of these multiples is 23.
//
// Find the sum of all the multiples of 3 or 5 below 1000.
fn compute(n: i32) -> i32 {
(0..n).filter(|x| x % 3 == 0 || x % 5 == 0).sum()
}
fn main() {
println!("the sum of all multiples of 3 or 5 below 1000 is: {}",
compute(1000));
}
#[test]
fn test() {
assert_eq!(23, compute(10));
assert_eq!(233168, compute(1000));
}