Guest User

Untitled

a guest
Dec 13th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #### Scenario 1
  2. **Inputs:**
  3. * Target number: 20
  4. * Number to get multiples: [3, 5]
  5.  
  6. **Output**
  7. * 78
  8. ---
  9. Algorithm
  10. 1. Create an empty array, called `multiples`, that will contain the list of multiples
  11.  
  12. `multiples = []`
  13. 2. Check if there are numbers to get multiples from. If there are none set it to [3, 5]
  14.  
  15. Retains inputs since there are numbers to get multiples from.
  16. 3. Loop over the list of numbers to get multiples from
  17.  
  18. `[3, 5]`
  19. 1. For every `number`, set the value of `current_number` to `number` to keep track of the incremented value.
  20.  
  21. `current_number = 3`; `current_number = 5`
  22. 2. Increment `current_number` by `number` while the value is less than the target number
  23.  
  24. `while current_number < 20; current_number = current_number + number`
  25. 1. Before every increment, add `current_number` to `multiples`
  26.  
  27. `multiples = [3]; multiples = [3, 6]; mutliples = [3, 6, 9] ...`
  28.  
  29. `... multiples = [3, 6, 9, 12, 15, 18, 5, 10, 15]`
  30. 4. Filter out the duplicate numbers from `multiples`
  31.  
  32. `multiples = [3, 6, 9, 12, 15, 18, 5, 10]`
  33. 5. Return the sum of the numbers in `multiples`
  34.  
  35. `78`
Add Comment
Please, Sign In to add comment