forked from ExplorerJun/java-baseball
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReferee.java
More file actions
28 lines (21 loc) · 741 Bytes
/
Referee.java
File metadata and controls
28 lines (21 loc) · 741 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
import java.util.Arrays;
import java.util.stream.IntStream;
public class Referee {
public int[] judge(int[] ansBallCombi, int[] inpBallCombi) {
int[] cnt = new int[10];
for (int ansPnt : ansBallCombi) {
cnt[ansPnt]++;
}
int strikeCnt = IntStream.range(0, inpBallCombi.length)
.map(i -> (ansBallCombi[i] == inpBallCombi[i]) ? 1 : 0)
.reduce((a, b) -> a + b)
.getAsInt();
int ballCnt = Arrays.stream(inpBallCombi)
.map(pnt -> cnt[pnt])
.reduce((a, b) -> a + b)
.getAsInt()
- strikeCnt;
int[] judgement = {strikeCnt, ballCnt};
return judgement;
}
}