Johnny is trying to create crossword puzzles, but he is having difficulty making words match each other.
He has come up with several simple word rectangles: that is, groups of words that form a rectangle where all horizontal and vertical paths form a word.
//2x2
PA
AM
//2x3
GOB
ORE
//3x3
BAG
AGO
RED
//3x4
MACE
AGES
WEES
However, to make a good puzzle, he needs some word rectangles that are somewhat larger than 3x4. Instead of agonizing over the arrangement letters for hours, Johnny would prefer to have a program that does this for him--and in as few characters as possible, because long blocks of code are extremely intimidating for casual programmers like Johnny.
Given
- a text file dictionary where words are separated by newlines in alphabetical order,
- input specifying the number of rows and columns in the words rectangle (which can be provided however is most convenient in your programming language of choice)
generate at least one word rectangle. If it is not possible to generate a word rectangle with the given lexicon and dimensions, the program need not have defined behaviour. It is not necessary for the program to be able to generate rectangles which contain more than 64 letters or have dimensions that exceed 8 in either direction. The program should be able to complete in a reasonable amount of time, say, in thirty minutes or less.
EDIT: If you are doing an NxN rectangle, you are permitted to use a smaller dictionary file that only contains words that have a length of N letters.