|
1 | 1 | # Instructions |
2 | 2 |
|
3 | | -Given a list of factors and a limit, add up all the unique multiples of the factors that are less than the limit. |
4 | | -All inputs will be greater than or equal to zero. |
| 3 | +Your task is to write the code that calculates the energy points that get awarded to players when they complete a level. |
5 | 4 |
|
6 | | -## Example |
| 5 | +The points awarded depend on two things: |
7 | 6 |
|
8 | | -Suppose the limit is 20 and the list of factors is [3, 5]. |
9 | | -We need to find the sum of all unique multiples of 3 and 5 that are less than 20. |
| 7 | +- The level (a number) that the player completed. |
| 8 | +- The base value of each magical item collected by the player during that level. |
10 | 9 |
|
11 | | -Multiples of 3 less than 20: 3, 6, 9, 12, 15, 18 |
12 | | -Multiples of 5 less than 20: 5, 10, 15 |
| 10 | +The energy points are awarded according to the following rules: |
13 | 11 |
|
14 | | -The unique multiples are: 3, 5, 6, 9, 10, 12, 15, 18 |
| 12 | +1. For each magical item, take the base value and find all the multiples of that value that are less than the level number. |
| 13 | +2. Combine the sets of numbers. |
| 14 | +3. Remove any duplicates. |
| 15 | +4. Calculate the sum of all the numbers that are left. |
15 | 16 |
|
16 | | -The sum of the unique multiples is: 3 + 5 + 6 + 9 + 10 + 12 + 15 + 18 = 78 |
| 17 | +Let's look at an example: |
17 | 18 |
|
18 | | -So, the answer is 78. |
| 19 | +**The player completed level 20 and found two magical items with base values of 3 and 5.** |
| 20 | + |
| 21 | +To calculate the energy points earned by the player, we need to find all the unique multiples of these base values that are less than level 20. |
| 22 | + |
| 23 | +- Multiples of 3 less than 20: `{3, 6, 9, 12, 15, 18}` |
| 24 | +- Multiples of 5 less than 20: `{5, 10, 15}` |
| 25 | +- Combine the sets and remove duplicates: `{3, 5, 6, 9, 10, 12, 15, 18}` |
| 26 | +- Sum the unique multiples: `3 + 5 + 6 + 9 + 10 + 12 + 15 + 18 = 78` |
| 27 | +- Therefore, the player earns **78** energy points for completing level 20 and finding the two magical items with base values of 3 and 5. |
0 commit comments