Rust - Solved Sum of Multiples

This commit is contained in:
Unknown 2017-04-27 20:51:10 -04:00
parent ed6f96f131
commit db7665b977

View file

@ -1,12 +1,17 @@
pub fn sum_of_multiples(x: i64, factors: &Vec<i64>) -> i64 { pub fn sum_of_multiples(x: i64, factors: &Vec<i64>) -> i64 {
let mut sum: i64 = 0; let mut unique_multiples: Vec<i64> = Vec::new();
for i in factors{ for i in factors{
for j in 2..x{ for j in 1..x{
if j % i == 0{ if j % i == 0{
// Need to figure out how to not add in duplicates if !unique_multiples.contains(&j){
sum += j; unique_multiples.push(j);
}
} }
} }
} }
let mut sum: i64 = 0;
for i in unique_multiples{
sum += i;
}
return sum; return sum;
} }