diff --git a/rust/sum-of-multiples/src/lib.rs b/rust/sum-of-multiples/src/lib.rs index 62d2bd0..5038596 100644 --- a/rust/sum-of-multiples/src/lib.rs +++ b/rust/sum-of-multiples/src/lib.rs @@ -1,12 +1,17 @@ pub fn sum_of_multiples(x: i64, factors: &Vec) -> i64 { - let mut sum: i64 = 0; + let mut unique_multiples: Vec = Vec::new(); for i in factors{ - for j in 2..x{ + for j in 1..x{ if j % i == 0{ - // Need to figure out how to not add in duplicates - sum += j; + if !unique_multiples.contains(&j){ + unique_multiples.push(j); + } } } } + let mut sum: i64 = 0; + for i in unique_multiples{ + sum += i; + } return sum; } \ No newline at end of file