Browse Source

problem 1

canon
Hazel Levine 1 year ago
parent
commit
9819cc89e6
4 changed files with 40 additions and 0 deletions
  1. +8
    -0
      .gitignore
  2. +9
    -0
      Cargo.toml
  3. +20
    -0
      src/bin/prob1.rs
  4. +3
    -0
      src/main.rs

+ 8
- 0
.gitignore View File

@ -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
- 0
Cargo.toml View File

@ -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
- 0
src/bin/prob1.rs View File

@ -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
- 0
src/main.rs View File

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

Loading…
Cancel
Save