-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGreed_is_Good.java
More file actions
35 lines (25 loc) · 791 Bytes
/
Greed_is_Good.java
File metadata and controls
35 lines (25 loc) · 791 Bytes
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
import java.util.HashMap;
import java.util.Map;
public class Greed {
private static final int[] valores = { 0, 1000, 200, 300, 400, 500, 600 };
private static int obtenerPuntuacion(Map<Integer, Integer> recuento) {
int puntos = 0;
for (Integer caras : recuento.keySet()) {
int contador = recuento.get(caras);
if (contador >= 3) {
contador -= 3;
puntos += valores[caras];
}
puntos += caras == 1 ? 100 * contador : 0;
puntos += caras == 5 ? 50 * contador : 0;
}
return puntos;
}
public static int greedy(int[] dice) {
Map<Integer, Integer> recuento = new HashMap<>();
for (int cara : dice) {
recuento.put(cara, recuento.getOrDefault(cara, 0) + 1);
}
return obtenerPuntuacion(recuento);
}
}