Skip to content

Instantly share code, notes, and snippets.

@wunki
Created March 20, 2014 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wunki/9664090 to your computer and use it in GitHub Desktop.
Save wunki/9664090 to your computer and use it in GitHub Desktop.
Euler - 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 is_multiple(num: int) -> bool {
num % 3 == 0 || num % 5 == 0
}
fn main() -> () {
let mut total = 0;
for n in range(0, 1000) {
if is_multiple(n) {
total += n
}
};
println!("Total is {:d}", total)
}
#[test]
fn test_seven_is_not_multiple() {
if is_multiple(7) {
fail!("7 is not a multiple of 3 or 5");
}
}
#[test]
fn test_five_is_multiple() {
if !is_multiple(5) {
fail!("Five is multiple of 5!")
}
}
#[test]
fn test_nine_is_multiple() {
if !is_multiple(9) {
fail!("Five is multiple of 9!")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment