diff --git a/src/main/java/edu/rpi/legup/puzzle/binary/rules/EliminateTheImpossibleDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/binary/rules/EliminateTheImpossibleDirectRule.java index 6f8ee3ea9..2898ed084 100644 --- a/src/main/java/edu/rpi/legup/puzzle/binary/rules/EliminateTheImpossibleDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/binary/rules/EliminateTheImpossibleDirectRule.java @@ -8,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 { @@ -22,37 +25,39 @@ public EliminateTheImpossibleDirectRule() { } // Function to generate all binary strings - static String generateAllBinaryStrings(int n, String arr, int i) + void generateAllBinaryStrings(double x, int poss, ArrayList possibilities) { - if (i == n) - { - return arr; + int count = (int)x; + int finalLen = poss; + + Queue q = new LinkedList(); + q.add("1"); + while (count-- > 0) { + String s1 = q.peek(); + q.remove(); + + String newS1 = s1; + int curLen = newS1.length(); + + int runFor = poss - curLen; + if(curLen < finalLen){ + + + for(int i = 0; i < runFor; i++){ + newS1 = "0" + newS1; + } + + } + + System.out.println(newS1); + possibilities.add(newS1); + String s2 = s1; + q.add(s1 + "0"); + q.add(s2 + "1"); } - // First assign "0" at ith position - // and try for all other permutations - // for remaining positions - arr = arr + "0"; - generateAllBinaryStrings(n, arr, i + 1); - - // And then assign "1" at ith position - // and try for all other permutations - // for remaining positions - arr = arr + "1"; - generateAllBinaryStrings(n, arr, i + 1); - - return null; } - public ArrayList binaryCombiniations(int numEmpty) { - - ArrayList possibilities = new ArrayList<>(); - String arr = ""; - if (generateAllBinaryStrings(numEmpty, arr, 0) != null) { - possibilities.add(arr); - } - return null; - } @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 @@ -63,6 +68,13 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem BinaryBoard origBoard = (BinaryBoard) transition.getParents().get(0).getBoard(); BinaryCell binaryCell = (BinaryCell) puzzleElement; + ArrayList result = new ArrayList(); + generateAllBinaryStrings(10,4,result); + + for(String s : result){ + System.out.println(s); + } + return "Grouping of Three Ones or Zeros not found TEST"; }