A lattice crossword is a variant of a crossword where exactly 4 words are arranged in the form of a lattice (like a '#' sign). Given 4 words, a, b, c and d, return the number of different lattice crosswords that can be created according to the following rules:
Each of the four given words must appear in the crossword exactly once.
Two of the four words must be printed horizontally, from left to right.
Two of the four words must be printed vertically, from top to bottom.
Each horizontal word must cross both vertical words (each through exactly one common letter).
Each vertical word must cross both horizontal words (each through exactly one letter).
The horizontal words must be separated by at least one row.
The vertical words must be separated by at least one column.
Two lattice crosswords are considered different if at least one of the words is at a different position. The position of a word is determined by the row and column position of its first letter. Row 0 is the row of the topmost letter in the crossword, and column 0 is the column of the leftmost letter in the crossword.
Here the leftmost letter is "t" of the "topcoder" and the topmost letter is "c" of the "contest".
So, the positions of the words are:
"topcoder" - (0, 4)
"contest" - (6, 0)
"problem" - (4, 2)
"solution" - (2, 6)
Another one lattice crossword, which can be constructed using this words is: