Rust - Solved Sum of Multiples
This commit is contained in:
parent
ed6f96f131
commit
db7665b977
1 changed files with 9 additions and 4 deletions
|
@ -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;
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue