Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. a n u
  2. r a s
  3. i u e
  4.  
  5. And i need to search ani, so, word exists taking an a from second row, n from first one and i from last one.
  6.  
  7. private static boolean search(String wordToSearch, char[][] matrixCube, int[][] solution, int searchLetterPosition) {
  8. if (solution[solution.length - 1][0] != -1) {
  9. printSolution(solution);
  10. return true;
  11. }
  12.  
  13. char letterToFound = wordToSearch.charAt(searchLetterPosition);
  14. for (int cube = 0; cube < matrixCube.length; cube++) {
  15. if (cubeIsFree(solution, cube)) {
  16. for (int faceInCube = 0; faceInCube < matrixCube[cube].length; faceInCube++) {
  17. boolean letterFounded = matrixCube[cube][faceInCube] == letterToFound;
  18. if (letterFounded) {
  19. solution[searchLetterPosition][0] = cube;
  20. solution[searchLetterPosition][1] = faceInCube;
  21. return search(wordToSearch, matrixCube, solution, searchLetterPosition + 1);
  22. }
  23. }
  24. }
  25. }
  26. return false;
  27. }
  28.  
  29. private static boolean cubeIsFree(int[][] solution, int cube) {
  30. for (int[] aSolution : solution) {
  31. if (aSolution[0] == cube) {
  32. return false;
  33. }
  34. }
  35. return true;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement