forked from woowacourse-precourse/java-baseball-6
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComputer.java
More file actions
29 lines (22 loc) · 786 Bytes
/
Computer.java
File metadata and controls
29 lines (22 loc) · 786 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
package baseball.domain;
import java.util.List;
import java.util.stream.IntStream;
public class Computer {
private final List<Integer> answer;
public Computer(List<Integer> answer) {
this.answer = answer;
}
public ComparisonResult compare(List<Integer> input) {
return new ComparisonResult(findStrike(input), findBall(input));
}
private int findStrike(List<Integer> input) {
return (int) IntStream.range(0, 3)
.filter(i -> answer.get(i).equals(input.get(i)))
.count();
}
private int findBall(List<Integer> input) {
return (int) IntStream.range(0, 3)
.filter(i -> !answer.get(i).equals(input.get(i)) && answer.contains(input.get(i)))
.count();
}
}