Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a n u
- r a s
- i u e
- And i need to search ani, so, word exists taking an a from second row, n from first one and i from last one.
- private static boolean search(String wordToSearch, char[][] matrixCube, int[][] solution, int searchLetterPosition) {
- if (solution[solution.length - 1][0] != -1) {
- printSolution(solution);
- return true;
- }
- char letterToFound = wordToSearch.charAt(searchLetterPosition);
- for (int cube = 0; cube < matrixCube.length; cube++) {
- if (cubeIsFree(solution, cube)) {
- for (int faceInCube = 0; faceInCube < matrixCube[cube].length; faceInCube++) {
- boolean letterFounded = matrixCube[cube][faceInCube] == letterToFound;
- if (letterFounded) {
- solution[searchLetterPosition][0] = cube;
- solution[searchLetterPosition][1] = faceInCube;
- return search(wordToSearch, matrixCube, solution, searchLetterPosition + 1);
- }
- }
- }
- }
- return false;
- }
- private static boolean cubeIsFree(int[][] solution, int cube) {
- for (int[] aSolution : solution) {
- if (aSolution[0] == cube) {
- return false;
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement