title: Algorithm for generating a grid with the given words shuffled like boggle - Word Brain
body: <p>There is this game inspired by Boggle about solving grid word puzzles where the letters of several secret words are placed seemingly randomly on a grid, but each word's letters are chained, the user being able to trace each word with a continuous line without taking the finger off screen.
  So the next letter in one word is neighbouring the preceding letter (either on N-W-S-E or on the diagonals).</p>
  
  <p>For instance, for the words WORD and BRAIN, a puzzle grid could be:</p>
  
  <pre><code>D A B
  R R I
  W O N
  </code></pre>
  
  <p>where to spell "WORD" you'd start from W, move east to O, then northwest to R, then north to D</p>
  
  <pre><code>D 
  R 
  W O
  </code></pre>
  
  <p>and, to spell 'BRAIN', you'd start from the B, then go southwest to the center R, then north to A, southeast to I and finally south to N.</p>
  
  <pre><code>  A B
    R I
      N
  </code></pre>
  
  <p>This is like reversed boggle, where only the puzzle's "secret" words are used in the grid, with no extra letters (except, depending on the number of letters in the words, some filler "white tiles" - which we can ignore for the sake of the question).</p>
  
  <p>I have read the <a href="https://stackoverflow.com/questions/23510229/which-algorithm-would-be-best-for-word-search-game-similar-with-boggle">other</a> posts about <a href="https://stackoverflow.com/questions/14191889/which-algorithm-would-fit-best-to-solve-a-word-search-game-like-boggle-with-py">algorithms</a> for solving this kind of game, but my question is, instead, on how I could go about to generate such puzzles - solvable shuffled grids with only letters from my initial words.</p>
  
  <p>I guess I could start with the trivial case of simply writing the words in sequence, rotating the letter matrix and/or making some simple cell permutations (swapping cells on two neighbouring lines / columns in order for the word to 'zig zag'. </p>
  
  <p>But I was wondering if there's a generating algorithm I could use (other than brute force randomly shuffling letters around until I find one  particular grid that's solvable).</p>