Rust Implementation of Problem 1

View source code here on GitHub!

pub fn problems::p0001::p0001() -> utils::Answer
 1/*
 2Project Euler Problem 1
 3
 4I did this in the traditional way, as I'm mostly using this folder as a way
 5to learn Rust
 6
 7Problem:
 8
 9If we list all the natural numbers below 10 that are multiples of 3 or 5, we
10get 3, 5, 6 and 9. The sum of these multiples is 23.
11
12Find the sum of all the multiples of 3 or 5 below 1000.
13*/
14use crate::include::utils::Answer;
15
16pub fn p0001() -> Answer {
17    let mut answer: u32 = 0;
18    for i in (0..1000).step_by(3) {
19        answer += i;
20    }
21    for i in (0..1000).step_by(5) {
22        answer += i;
23    }
24    for i in (0..1000).step_by(15) {
25        answer -= i;
26    }
27    return Answer::Int(answer.into());
28}

Tags: divisibility