This is a JavaScript program that is able to solve an empty crossword puzzle.
The main function is crosswordSolver
which takes two arguments:
- An empty puzzle, passed as a string, and;
- A list of words to fill in the puzzle (no double words allowed).
The function prints on the console a string representing the puzzle filled with the input words.
The empty puzzle must be a string with the following rules:
- Each character is be either a
number
, a.
or a\n
; - A
number
represents the number of words starting from the specific position; - A dot
.
represents a space that does not need to be filled.
If the puzzle or list of words provided as inputs does not guarantee a unique solution, or any other conditions stated above are not met, the function prints 'Error'.
-
Make sure that node runtime is installed on your machine.
-
Clone the repository:
git clone https://learn.zone01oujda.ma/git/asadiqui/crossword.git
- Provide inputs:
const emptyPuzzle = `2001
0..0
1000
0..0`;
const words = ['casa', 'alan', 'ciao', 'anta'];
crosswordSolver(emptyPuzzle, words);
- Run the program:
node crosswordSolver.js
- Enjoy the solution:
casa
i..l
anta
o..n
- You can also run a test:
node crosswordSolverTest.js
This project is open-sourced under the MIT License.