4 changed files with 40 additions and 0 deletions
@ -0,0 +1,9 @@
|
||||
[package] |
||||
name = "euler" |
||||
version = "0.1.0" |
||||
authors = ["Hazel Levine <rose.hazel@protonmail.ch>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
@ -0,0 +1,20 @@
|
||||
// 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)); |
||||
} |
Loading…
Reference in new issue