Problem Statement
John has a cactus. Sadly, John has only one cactus, and that cactus is lonely. Recently, however, John won $50,000, so he decided to buy some friends for his cactus. Now, everybody knows that the best cactuses in the world can be found at TopCactus.com. TopCactus.com has thousands and thousands of cactuses, and new ones arrive every day. They have so many, that they do not even have time to put prices on all of them. We are not interested in cactuses that do not yet have prices. Now, there are two kinds of priced cactuses. Some of them do not have flowers, and are by themselves gray or green. John does not want any of those. There are also cactuses with flowers. Cactuses with blue flowers are sold for prices ranging from $1,200 to $1,499 inclusive, those with yellow flowers go for between $1,500 and $2,199 inclusive, and those with red flowers cost between $2,200 and $2,999 inclusive. Also, there is a very small number of very, very rare cactuses, which have flowers that are red with a white center. These cactuses cost $3,000 or more and they are so unique and incomparable to each other that no two of them are ever sold for the same price.
Your task is, given the amount of money John spent buying cactuses from TopCactus.com and the number of very rare red-and-white cactuses available at TopCactus, return the number of different combinations of colors of cactuses there are that John could have bought.
For example, if John spent $3,500 and there was at least one very rare cactus: he could have bought one very rare red and white cactus for $3,500; or he could have bought one red cactus and one blue cactus; or two yellow cactuses; or a more expensive yellow and a blue. Return 4.
Definition
- Class:
- Cactus
- Method:
- colorCombo
- Parameters:
- int, int
- Returns:
- int
- Method signature:
- int colorCombo(int moneyGone, int numRare)
- (be sure your method is public)
Notes
- Though every cactus is unique and special, and even has its own name, for our purpose of counting color combinations, we consider different cactuses with the same color of flowers to be identical (so a blue cactus for $1,200 and a red cactus for $2,500 is not a different combination from a blue cactus for $1,400 and a red cactus for $2,300).
- The more expensive a cactus, the more difficult it is to grow or find, of course, so they are less common, but John does not have enough money to exhaust the supply of TopCactus.com of any color of cactus, except the very rare ones with red-and-white flowers, of which TopCactus can have up to five exemplars.
- We do not know the actual prices of the individual cactuses because they change nearly every week, so we assume that, if John wanted to, he could buy a cactus with a given color of flowers for any price within that range. (In particular, he might blow all $50,000 on a single cactus!)
- As an exception to that, though, we know that the very rare cactuses with red-and-white flowers have very different personalities (for instance, one of them has a tendency to snap at people) so no two of them are ever the same price.
Constraints
- moneyGone is between 1200 and 50000 inclusive
- numRare is between 0 and 5 inclusive
Examples
3500
4
Returns: 4
6000
3
Returns: 18
Note that John couldn't have bought two very rare red-and-white cactuses as they should be different in price
50000
5
Returns: 21233
2002
5
Returns: 1
20000
1
Returns: 574
50000
0
Returns: 3526
6001
3
Returns: 19
4500
5
Returns: 8
47000
0
Returns: 2949
50000
1
Returns: 8625
2999
5
Returns: 2
3000
5
Returns: 3
46999
1
Returns: 7120
50000
2
Returns: 12825
1533
4
Returns: 1
49999
4
Returns: 18972
49999
5
Returns: 21171
5999
3
Returns: 15
6099
5
Returns: 19
6100
5
Returns: 20
49983
0
Returns: 3493
49980
0
Returns: 3496
49982
0
Returns: 3494
49981
0
Returns: 3495
49980
1
Returns: 8566
49999
1
Returns: 8563
49982
1
Returns: 8564
49981
1
Returns: 8565
3500
0
Returns: 3
Observe that here, as opposed to in example 0, there are no very rare cactuses at TopCactus.com, so John could not have bought any of them.
49012
0
Returns: 3332
Ten random test cases
43512
1
Returns: 5694
11145
0
Returns: 55
12586
1
Returns: 146
22791
2
Returns: 1123
17836
0
Returns: 194
7916
0
Returns: 23
33937
0
Returns: 1158
3411
3
Returns: 4
47137
4
Returns: 15752
49999
5
Returns: 21171
15003
5
Returns: 341
50000
5
Returns: 21233
9002
5
Returns: 63
10201
5
Returns: 97