Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private ArrayList<ArrayList<Integer>> solve(int n) {
- int solutionCount = 0;
- if (n == ironRod.size()) {
- return ironRod; // base case
- }
- int rotationCount = 0;
- boolean solved = false;
- while (!solved) {
- solved = true;
- for (int j = 1; j < n; j++) {
- if ( shareSides(ironRod.get(n), ironRod.get(j)) ) { // tests if cubes share sides
- solved = false;
- break;
- } // end if
- } // end for
- if (solved && (solve(n+1) != null)) {
- if (solutionCount++ < 5) {
- System.out.println(ironRod);
- return null;
- }
- }
- else {
- solved = false;
- ironRod.set(n, this.rotate(ironRod.get(n)));
- rotationCount += 1;
- if (rotationCount > 3)
- return null;
- } // end else
- } // end while
- return null;
- } // end solve(int n)
Add Comment
Please, Sign In to add comment