Skip to content

Commit

Permalink
Added row functionality for eliminate the impossible
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharybonagura committed Jul 9, 2024
1 parent b5c10be commit b527b9a
Showing 1 changed file with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,12 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem

System.out.println("Number of possible binary combinations: " + rowCopies.size());

ArrayList<ArrayList<BinaryCell>> nonContraRows = new ArrayList<>();
int rowIdx = 0;
for(ArrayList<BinaryCell> curRow : rowCopies){
int charIdx = 0;
System.out.println(rowResult.get(rowIdx));
for(int i = 0; i < curRow.size(); i++ ) {
for(int i = 0; i < curRow.size(); i++) {
if (curRow.get(i).getData() == 2) {
if (rowResult.get(rowIdx).charAt(charIdx) == '0') {
curRow.get(i).setData(0);
Expand All @@ -152,10 +153,43 @@ else if (rowResult.get(rowIdx).charAt(charIdx) == '1') {
}
System.out.print(curRow.get(i).getData() + " ");
}

boolean threeAdjacent = false;
int count = 1;
for(int i = 1; i < curRow.size(); i++) {
if (curRow.get(i).getData() == curRow.get(i-1).getData()) {
count++;
if (count == 3) {
threeAdjacent = true;
break;
}
} else {
count = 1;
}
}

if (!threeAdjacent) {
nonContraRows.add(curRow);
}

rowIdx++;
System.out.println();
}

System.out.println("Number of non contradiction rows: " + nonContraRows.size());
int colNum = binaryCell.getLocation().x;
boolean invalid = false;
for(int i = 0; i < nonContraRows.size(); i++) {
if (nonContraRows.get(i).get(colNum).getData() != binaryCell.getData()) {
invalid = true;
break;
}
}

if (!invalid) {
return null;
}

return "Grouping of Three Ones or Zeros not found";

}
Expand Down

0 comments on commit b527b9a

Please sign in to comment.