Skip to content

Commit

Permalink
finished the generate possibilites function for ETP
Browse files Browse the repository at this point in the history
  • Loading branch information
ContemporaryNietzsche committed Jun 22, 2024
1 parent c3265d3 commit 7049e9f
Showing 1 changed file with 38 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,62 @@ public EliminateTheImpossibleDirectRule() {
}

// Function to generate all binary strings
void generateAllBinaryStrings(double countTo, int spots, ArrayList<String> possibilities)
void generatePossibilitites(int spots, ArrayList<String> possibilities, int zeroCount, int oneCount)
// This function generates all the possible combinations of 0s and 1s for a certain size, it does this
// by basically just counting from 0 to the number - 1, so if you want all the possible combinations for 3
// spots, you can just count in binary from 0 to 7 (taking 3 spots, so from 000 to 111). To be practical,
// the function does not return an array with all the possibilities as an array, but populates the
// arraylist you pass in (possibilities)
{
int count = (int)countTo;
if(zeroCount + oneCount != spots){
System.out.println("INVALID INPUT");
return;
}

if(zeroCount == spots){
String zero = "";
for(int i = 0; i < spots; i++){
zero = zero + "0";
}
possibilities.add(zero);

}
int count = (int)Math.pow(2,spots) -1;
int finalLen = spots;

Queue<String> q = new LinkedList<String>();
q.add("1");

while (count-- > 0) {
String s1 = q.peek();
q.remove();

String newS1 = s1;
int curLen = newS1.length();

int runFor = spots - curLen;
if(curLen < finalLen){


for(int i = 0; i < runFor; i++){
newS1 = "0" + newS1;
}

}

System.out.println(newS1);
possibilities.add(newS1);
int curZeros = 0;
int curOnes = 0;

for(int i = 0; i < spots; i++){
if(newS1.charAt(i) == '0'){
curZeros++;
}
if(newS1.charAt(i) == '1'){
curOnes++;
}
}

if(zeroCount == curZeros && oneCount == curOnes){
possibilities.add(newS1);
}
String s2 = s1;
q.add(s1 + "0");
q.add(s2 + "1");
}

}
}

@Override
Expand All @@ -74,8 +94,12 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
BinaryCell binaryCell = (BinaryCell) puzzleElement;

ArrayList<String> result = new ArrayList<String>();
generateAllBinaryStrings(16,4,result);

int zerosLeft = 3;
int onesLeft = 1;
generatePossibilitites(4, result, zerosLeft, onesLeft);

System.out.println("printing result");
for(String s : result){
System.out.println(s);
}
Expand Down

0 comments on commit 7049e9f

Please sign in to comment.