Problem Statement
A machine is programmed to automatically mix two chemicals. The machine begins with Bowl A filled with 360000 units of chemical 1 and Bowl B filled with 360000 units of chemical 2. Define a "mix" as follows:
- The machine pours 120000 units of liquid from Bowl A to Bowl B and stirs Bowl B until the liquid is well mixed.
- The machine pours 120000 units of liquid from Bowl B to Bowl A and stirs Bowl A until the liquid is well mixed.
Given an int mixes, return the number of units of chemical 1 in Bowl B after the machine performs the above procedure mixes amount of times.
If the amount of chemical 1 that needs to make up the 120000 units for pouring is not an integer, then round down the number of chemical 1 units for pouring. For example, if there are 180001 units of chemical 1 out of 360000 in Bowl A, then to pour 120000 units into Bowl B, there should be 60000.33 units of chemical 1 in the 120000, so just consider the 120000 units to be 60000 parts chemical 1, 60000 parts chemical 2. Similarly, if there are 240001 units of chemical 1 out of 480000 in Bowl B, then to pour 120000 units back into Bowl A, there should be 60000.25 units of chemical 1, so just consider the 120000 units to be 60000 parts chemical 1, 60000 parts chemical 2.
Definition
- Class:
- ChemMix
- Method:
- partsChem
- Parameters:
- int
- Returns:
- int
- Method signature:
- int partsChem(int mixes)
- (be sure your method is public)
Constraints
- mixes is an int between 0 and 100, inclusive.
Examples
0
Returns: 0
If there has not been any mixing done, then the amount of chemical 1 in Bowl B has not changed.
1
Returns: 90000
After pouring from bowl A to bowl B, bowl A has 240000 units of chemical 1 and bowl B has 120000 units of chemical 1 (and 360000 parts chemical 2). Then, after pouring from bowl B to bowl A, 1/4 of the 120000 units are chemical 1 units, so 30000 chemical 1 units are returned to bowl A. Bowl B now has 120000 - 30000 = 90000.
5
Returns: 174375
100
Returns: 180000
17
Returns: 179999
19
Returns: 180000
20
Returns: 180000
70
Returns: 180000
18
Returns: 180000
26
Returns: 180000
72
Returns: 180000
97
Returns: 180000
56
Returns: 180000
1
Returns: 90000
8
Returns: 179297
52
Returns: 180000
13
Returns: 179979
100
Returns: 180000
79
Returns: 180000