Generating questions

  1. Send request to [https://api.datamuse.com/words?](<https://api.datamuse.com/words?md=d&sp=>)sp=?*length_of_word&md=d&max=1000 and save returned words to cache.
  2. Randomly choose a word from the cache that fits in the crossword.
  3. If no word from the cache fits, repeat steps 1-2 but in request address replace question marks with known letters of this word.
  4. If no word is found, repeat steps 1-3 for the previous, excluding the word which was already chosen. If there is no previous word, the crossword can’t be generated.
  5. Update matrix with chosen word letters instead of 1.
  6. Call generation of the next word.

Solving questions

  1. Send request to [https://api.datamuse.com/words?](<https://api.datamuse.com/words?md=d&sp=>)ml=user_question&sp=?*length_of_word, get the words and save them as possible answers.
  2. Repeat for all words.
  3. Call solve for the first word.
  4. If the word has no intersections with known letters, suppose the first possible answer is right.
  5. If it does, find a word that fits known letters and remove it from possible answers. If no word is found, return to the previous word. If there is no previous word, the crossword can’t be solved.
  6. If the word has been chosen:
    1. Update matrix with a chosen word.
    2. Call next word by id.