-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathFrobeniusCoinProblem.java
41 lines (36 loc) · 1.21 KB
/
FrobeniusCoinProblem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package by.andd3dfx.numeric;
import by.andd3dfx.dynamic.ChangeWithMinNumberOfCoins;
/**
* <pre>
* Find the largest monetary amount that cannot be obtained using only coins of specified denominations.
*
* See <a href="https://en.wikipedia.org/wiki/Coin_problem">article</a> in wiki
* </pre>
*
* @see <a href="https://youtu.be/itBWtCwWUG4">Video solution</a>
*/
public class FrobeniusCoinProblem {
public static int find(int[] nominals) {
var capAmount = determineStartingValueEnhanced(nominals);
for (var amount = capAmount; amount >= 1; amount--) {
if (ChangeWithMinNumberOfCoins.determine_usingMemoization(nominals, amount) == -1) {
return amount;
}
}
return 1;
}
/**
* Method wasn't deleted for demo purposes
*/
private static int determineStartingValuePrimitive(int[] nominals) {
var result = 1;
for (int nominal : nominals) {
result *= nominal;
}
System.out.println(result);
return result;
}
private static int determineStartingValueEnhanced(int[] nominals) {
return LeastCommonMultiple.find(nominals);
}
}