Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
39
Task/Bulls-and-cows-Player/Java/bulls-and-cows-player-2.java
Normal file
39
Task/Bulls-and-cows-Player/Java/bulls-and-cows-player-2.java
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
public abstract class AbstractGuessNumber {
|
||||
|
||||
protected int[] digits;
|
||||
private int length;
|
||||
|
||||
public AbstractGuessNumber(int length) {
|
||||
this.length = length;
|
||||
this.digits = new int[this.length];
|
||||
}
|
||||
|
||||
public int[] getDigits() {
|
||||
return digits;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public GuessResult match(AbstractGuessNumber guessable) {
|
||||
int bulls = 0;
|
||||
int cows = 0;
|
||||
|
||||
if (guessable != null) {
|
||||
for (int i = 0; i < this.getLength(); i++) {
|
||||
for (int j = 0; j < guessable.getLength(); j++) {
|
||||
|
||||
if (digits[i] == guessable.getDigits()[j]) {
|
||||
if (i == j) {
|
||||
bulls++;
|
||||
} else {
|
||||
cows++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new GuessResult(getLength(), bulls, cows);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue