Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #### Scenario 1
- **Inputs:**
- * Target number: 20
- * Number to get multiples: [3, 5]
- **Output**
- * 78
- ---
- Algorithm
- 1. Create an empty array, called `multiples`, that will contain the list of multiples
- `multiples = []`
- 2. Check if there are numbers to get multiples from. If there are none set it to [3, 5]
- Retains inputs since there are numbers to get multiples from.
- 3. Loop over the list of numbers to get multiples from
- `[3, 5]`
- 1. For every `number`, set the value of `current_number` to `number` to keep track of the incremented value.
- `current_number = 3`; `current_number = 5`
- 2. Increment `current_number` by `number` while the value is less than the target number
- `while current_number < 20; current_number = current_number + number`
- 1. Before every increment, add `current_number` to `multiples`
- `multiples = [3]; multiples = [3, 6]; mutliples = [3, 6, 9] ...`
- `... multiples = [3, 6, 9, 12, 15, 18, 5, 10, 15]`
- 4. Filter out the duplicate numbers from `multiples`
- `multiples = [3, 6, 9, 12, 15, 18, 5, 10]`
- 5. Return the sum of the numbers in `multiples`
- `78`
Add Comment
Please, Sign In to add comment