Inputs:
- Target number: 20
- Number to get multiples: [3, 5]
Output
- 78
Algorithm
-
Create an empty array called
multiplesthat will contain the list of multiplesmultiples = [] -
Check whether the list of factors is empty. If there are no factors, set the list to
[3, 5][3, 5]obtained from supplied factors. -
For every
factorin thefactorslist:[3, 5]-
Set the
current_multipletofactorto keep track of the multiples offactor.current_multiple = 3 current_multiple = 5
-
While
current_multiple<target-
Append the
current_multipletomultiples.multiples = [3] multiples = [3, 6] multiples = [3, 6, 9] ... multiples = [3, 6, 9, 12, 15, 18, 5, 10, 15]
-
Add
factortocurrent_multiple.current_multiple = 6 current_multiple = 9 ... current_multiple = 18 current_multiple = 21 current_multiple = 5 current_multiple = 10 current_multiple = 15 current_multiple = 20
-
-
-
Filter duplicate numbers from
multiples.multiples = [3, 6, 9, 12, 15, 18, 5, 10] -
Compute and return the sum of the numbers in
multiples.78