From db7665b977b4c77e113cc3cfce7d64fdf833f70e Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 27 Apr 2017 20:51:10 -0400 Subject: [PATCH] Rust - Solved Sum of Multiples --- rust/sum-of-multiples/src/lib.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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