Browse Source

problem 1

canon
Hazel Levine 4 years ago
parent
commit
9819cc89e6
  1. 8
      .gitignore
  2. 9
      Cargo.toml
  3. 20
      src/bin/prob1.rs
  4. 3
      src/main.rs

8
.gitignore vendored

@ -10,3 +10,11 @@ Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
#Added by cargo
#
#already existing elements are commented out
/target
#**/*.rs.bk

9
Cargo.toml

@ -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]

20
src/bin/prob1.rs

@ -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));
}

3
src/main.rs

@ -0,0 +1,3 @@
fn main() {
println!("haha yes, very good code good yes");
}
Loading…
Cancel
Save