daily pastebin goal
47%
SHARE
TWEET

Untitled

a guest May 16th, 2018 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private ArrayList<ArrayList<Integer>> solve(int n) {
  2.       int solutionCount = 0;
  3.      
  4.       if (n == ironRod.size()) {
  5.          return ironRod; // base case
  6.       }
  7.       int rotationCount = 0;
  8.       boolean solved = false;
  9.       while (!solved) {
  10.          solved = true;
  11.          for (int j = 1; j < n; j++) {
  12.             if ( shareSides(ironRod.get(n), ironRod.get(j)) ) { // tests if cubes share sides
  13.                
  14.                solved = false;
  15.                break;
  16.             } // end if
  17.          } // end for
  18.  
  19.          if (solved && (solve(n+1) != null)) {
  20.            
  21.             if (solutionCount++ < 5) {
  22.                System.out.println(ironRod);
  23.                return null;
  24.             }
  25.          }
  26.          else {
  27.             solved = false;
  28.             ironRod.set(n, this.rotate(ironRod.get(n)));
  29.             rotationCount += 1;
  30.             if (rotationCount > 3)
  31.                return null;
  32.          } // end else
  33.  
  34.       } // end while
  35.       return null;
  36.    } // end solve(int n)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top