Skip to content

Commit

Permalink
Merge pull request #827 from ContemporaryNietzsche/binary
Browse files Browse the repository at this point in the history
Binary
  • Loading branch information
zacharybonagura authored Jun 23, 2024
2 parents c3fb60d + 7049e9f commit 3350325
Showing 1 changed file with 70 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package edu.rpi.legup.puzzle.binary.rules;


import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.rules.DirectRule;
Expand All @@ -9,6 +8,9 @@
import edu.rpi.legup.puzzle.binary.BinaryBoard;
import edu.rpi.legup.puzzle.binary.BinaryCell;

import java.util.LinkedList;
import java.util.Queue;
import java.lang.Math.*;
import java.util.ArrayList;

public class EliminateTheImpossibleDirectRule extends DirectRule {
Expand All @@ -23,43 +25,86 @@ public EliminateTheImpossibleDirectRule() {
}

// Function to generate all binary strings
static String generateAllBinaryStrings(int n, String arr, int i)
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)
{
if (i == n)
{
return arr;
if(zeroCount + oneCount != spots){
System.out.println("INVALID INPUT");
return;
}

// First assign "0" at ith position
// and try for all other permutations
// for remaining positions
arr = arr + "0";
generateAllBinaryStrings(n, arr, i + 1);
if(zeroCount == spots){
String zero = "";
for(int i = 0; i < spots; i++){
zero = zero + "0";
}
possibilities.add(zero);

// And then assign "1" at ith position
// and try for all other permutations
// for remaining positions
arr = arr + "1";
generateAllBinaryStrings(n, arr, i + 1);
}
int count = (int)Math.pow(2,spots) -1;
int finalLen = spots;
Queue<String> q = new LinkedList<String>();
q.add("1");

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

public ArrayList<String> binaryCombiniations(int numEmpty) {
String newS1 = s1;
int curLen = newS1.length();
int runFor = spots - curLen;
if(curLen < finalLen){
for(int i = 0; i < runFor; i++){
newS1 = "0" + newS1;
}
}
int curZeros = 0;
int curOnes = 0;

ArrayList<String> possibilities = new ArrayList<>();
String arr = "";
if (generateAllBinaryStrings(numEmpty, arr, 0) != null) {
possibilities.add(arr);
}
return null;
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
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
// This function should first check if there are three open spaces, if so, continue, else figure out
// how many spots are open, all the possible binary combinations that could be put there, and by
// analyzing the common factors, logically determine which number has a set spot, meaning that we know
// that a certain spot must be a zero or a one

BinaryBoard origBoard = (BinaryBoard) transition.getParents().get(0).getBoard();
BinaryCell binaryCell = (BinaryCell) puzzleElement;

return "Grouping of Three Ones or Zeros not found";
ArrayList<String> result = new ArrayList<String>();

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

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

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

@Override
Expand Down

0 comments on commit 3350325

Please sign in to comment.