title: Java Word Search Solver Design Approach
body: <p>I am writing a program that is a word search solver and was curious if there was a better approach than what I was taking. The program contains a grid of characters that are suppose to be the puzzle followed by a line break and words to be located in the matrix.  </p>
  
  <p>My question is that in locating for the beginning and ending characters of each string would it be better to just strong arm it through the puzzle with nested loops for each direction or could this process be streamlined using some sort of straight line detection algorithm? </p>
  
  <p>The Words can be horizontal, vertical or diagonal and the reverse of each.  </p>
  
  <p>Really what I am looking to do is plot the beginning and ending points of a char array (The Word) inside the 2d char array (Puzzle)</p>
  
  <p>Example of puzzle<br>
  HGAMONIHRA<br>
  AOMOKAWONS<br>
  NFROLBOBDN<br>
  ARFSIHCAGE<br>
  LNIEEWONOK<br>
  GOLFUNDTHC<br>
  KOCATAOHBI<br>
  AMRERCGANH<br>
  SLGFAMALLC<br>
  ALLIGATORX  </p>
  
  <p>HORSE<br>
  COW<br>
  RHINO<br>
  JABBERWOCKY<br>
  CAT<br>
  DOG<br>
  ALLIGATOR<br>
  CHICKEN<br>
  FROG<br>
  BANTHA<br>
  MOOSE<br>
  LLAMA  </p>
  
  <p>Assuming I use just a series of loops I am unsure of the best way to do that to check in all the directions. So far I just have it working searching the words horizontally </p>
  
  <pre><code>                boolean over = false;
                  boolean foundit = false;
                  String word = new String(letters);
  
                  for (int i = 0; (i &lt; puzzle.length) &amp;&amp; (!over); i++) {
                      for (int j = 0; (j &lt; puzzle[i].length) &amp;&amp; (!over); j++) {
  
                          // Use (i,j) as the starting point.
                          foundit = true;
  
                          // Look through each letter in word
                          for (int k = 0; (k &lt; letters.length) &amp;&amp; (foundit); k++) {
                              if ((j + k &gt;= puzzle[i].length)
                                      || (letters[k] != puzzle[i][j + k])) {
                                  // It didn't Match
                                  foundit = false;
                              }
                          }
                          // Success if we made it through all the characters
                          if (foundit) {
                              System.out.println(word + " found in row=" + i
                                      + " col=" + j);
                              over = true;
                          }
  
                      }
                  }
  
                  if (!foundit) {
                      System.out.println(word + " not found");
                  }
  </code></pre>
  
  <p>Any Pointers on finding them vertically, diagonal and reverse?</p>