Generate wordsearch puzzles


Generate wordsearch puzzles

In the browser

<script src="wordsearch.min.js"></script>
<!-- // defines wordsearch() -->

In Node.js

npm install wordsearch

...and then

var wordsearch = require('wordsearch');

Create a simple wordsearch puzzle

> var wordsearch
> var search = wordsearch(['hi', 'dave'], 4, 4);
> search.grid
[ [ 't', 't', 'j', 'b' ],
  [ 'n', 'i', 's', 'w' ],
  [ 'h', 'd', 'i', 'q' ],
  [ 'd', 'a', 'v', 'e' ] ]
> search.grid.forEach(function(row) { console.log(row.join(' ')); } );
t t j b
n i s w
h d i q
d a v e
> search.solved
[ [ ' ', ' ', ' ', ' ' ],
  [ ' ', 'i', ' ', ' ' ],
  [ 'h', ' ', ' ', ' ' ],
  [ 'd', 'a', 'v', 'e' ] ]
> search.solved.forEach(function(row) { console.log(row.join(' ')); } );
d a v e
> search.unplaced
  • array: an array of words to put in the puzzle
  • width: the width of the puzzle, defaults to 20
  • height: the height of the puzzle, defaults to 20
  • opts: an optional object for options
    • opts.color: color code (ANSI) the words in the puzzle, defaults to false
    • opts.backwards: the probability between 0 and 1 (inclusive) of placing words backwards, defaults to 0.5

Installation and usage

$ npm install -g wordsearch
$ wordsearch --help
Usage: wordsearch [-f wordfile] [-d WidthxHeight] [options]

Generate wordsearch puzzles

  -c, --color        colorize the words in the puzzle, defaults to false
  -d, --dimensions   the dimensions of the puzzle, ex `-d 20`, `-d 10x8`, defaults to `20x20`
  -f, --file         a newline separated list of words to use, defaults to stdin
  -h, --help         print this message and exit
  -s, --solved       print the solved puzzle as well as the actual puzzle
  -u, --updates      check for available updates
  -v, --version      print the version number and exit


$ wordsearch -f example-words.txt -d 10x10 -s
failed to place 3 words: teenzone,whatever,skateboards
r e t w e e t s    
c     y t r a p    
  h     m u s i c  
      l l s w a g  
      o l          
    o     i        
  c         n      
        l o l      

puzzle for example-words.txt (8 words to find)
k v w g x s a z e x
r e t w e e t s j r
c d p y t r a p y c
n h g m m u s i c x
s l i o s j q o e b
n g v l l s w a g o
w a d o l r e r z f
y v o h y i e k m g
z c s c z w n z f p
d u w m l o l l i a