This article is part of a series where I'll be diving head first into the Project Euler puzzles. I want to document the challenge of solving such a puzzle and how I got to the answer. I want to prefix this by stating that I can't cheat for any of these challenges; with that I mean I can't look up any other implementations online. After the implementation, I will validate the answer by using this document or a similar sheet.
In this article I'll be solving: Project Euler #1.
This article features only an answer, because I’ve started writing from problem 14.
fn multiples_of_3_and_5(n: i32) -> i32 {
let mut total: i32 = 0;
for i in 0..n {
if i % 3 == 0 || i % 5 == 0 {
total += i
}
};
total
}
#[test]
fn find_multiples_of_3_and_5() {
assert_eq!(multiples_of_3_and_5(10), 23);
assert_eq!(multiples_of_3_and_5(1000), 233168);
}
The full solution is available on GitHub.