(String expression, HashMap<String, Boolean> completed, boolean result, boolean[] flags)
| 137 | } |
| 138 | |
| 139 | public static int bruteForce(String expression, HashMap<String, Boolean> completed, boolean result, boolean[] flags) { |
| 140 | int count = 0; |
| 141 | boolean isDone = true; |
| 142 | if (completed.containsKey(expression)) { |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | for (int i = 0; i < flags.length; i++) { |
| 147 | if (!flags[i]) { |
| 148 | flags[i] = true; |
| 149 | String newexpression = insertParensAround(expression, i); |
| 150 | isDone = false; |
| 151 | count += bruteForce(newexpression, completed, result, flags); |
| 152 | flags[i] = false; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | if (isDone) { |
| 157 | if (evaluate(expression, 0, expression.length() - 1) == result) { |
| 158 | System.out.println(expression + " = " + result); |
| 159 | return 1; |
| 160 | } else { |
| 161 | System.out.println(expression + " = " + !result); |
| 162 | return 0; |
| 163 | } |
| 164 | } |
| 165 | completed.put(expression, true); |
| 166 | return count; |
| 167 | } |
| 168 | |
| 169 | public static int countR(String exp, boolean result, int start, int end) { |
| 170 | if (start == end) { |
no test coverage detected