Skip to content

JavaScript program to solve crossword puzzle using greedy algorithm

Notifications You must be signed in to change notification settings

sadiqui/crossword-solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Crossword

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'.

Usage

  1. Make sure that node runtime is installed on your machine.

  2. Clone the repository:

git clone https://learn.zone01oujda.ma/git/asadiqui/crossword.git
  1. Provide inputs:
const emptyPuzzle = `2001
0..0
1000
0..0`;

const words = ['casa', 'alan', 'ciao', 'anta'];

crosswordSolver(emptyPuzzle, words);
  1. Run the program:
node crosswordSolver.js
  1. Enjoy the solution:
casa
i..l
anta
o..n
  1. You can also run a test:
node crosswordSolverTest.js

License

This project is open-sourced under the MIT License.

About

JavaScript program to solve crossword puzzle using greedy algorithm

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published