Note that there are some explanatory texts on larger screens.

plurals
  1. POWord search in a puzzle
    primarykey
    data
    text
    <p>newbie here i have written a code to search for words in a puzzle but the word search does not seem to return anything after i run the program. i stored the dictionary in a binary tree. i need to check the every combination of characters against that in my tree.Could you please help. Thank you....</p> <p>this is the solve method</p> <pre><code>public String solve() { int row = puzzle.length; int coloumns = puzzle[0].length; this.foundWords = new ArrayList&lt;String&gt;(); if (this.dictionary == null) return null; for (int i = 0; i &lt; this.puzzle[0].length; ++i) { for (int j = 0; j &lt; this.puzzle.length; ++j) { if (this.getWord(i, j, 0, 1) == null) continue; if(this.inDictionary(this.getWord(i,j,0,1))) this.foundWords.add(getWord(i,j,0,1).concat("\n" + this.mapDirection(0))); for(int d = 0; d&lt;8; ++d) { int n = 2; String word = this.getWord(i,j,d,n); while(word !=null) { if(this.inDictionary(word)) this.foundWords.add(word.concat("\n" + this.mapDirection(d))); word = this.getWord(i,j,d,n); n++; } } } } String temp = ""; for(int i= 0; i &lt; foundWords.size(); i++) { temp = temp.concat(foundWords.get(i)); } return temp; } </code></pre> <p>this gets the word..</p> <pre><code>public String getWord(int row, int column, int d, int length) { if (length &lt; 1) return null; d %= 8; StringBuilder rBuild = new StringBuilder(); rBuild.append(this.puzzle[row][column]); length--; while (length &gt;= 0) { if ((d == 3) || (d == 4) || (d == 5)) column--; if ((d == 1) || (d == 0) || (d == 7)) column++; if ((d == 1) || (d == 2) || (d == 3)) row--; if ((d == 5) || (d == 6) || (d == 7)) row++; if ((row &lt; 0) || (row &gt;= this.puzzle.length) || (column &lt; 0) || (column &gt;= this.puzzle[0].length)) return null; rBuild.append(this.puzzle[row][column]); length--; } return rBuild.toString(); } </code></pre> <p>for the direction..</p> <pre><code>public String mapDirection(int direction) { direction %=8; switch(direction) { case 0: return " right"; case 1: return " up and right"; case 2: return " up"; case 3: return " up and left"; case 4: return " left"; case 5: return " down and left"; case 6: return " down and left"; case 7: return " down and right"; } return null; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload