We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Recursion
- Crossword Puzzle
- Discussions
Crossword Puzzle
Crossword Puzzle
Sort by
recency
|
200 Discussions
|
Please Login in order to post a comment
Easy DFS with backtracking, had to do to refresh the concept or to get involve in brain tickling, here my solution c++ with explanation - 200 lines of self code
https://gist.github.com/yadav26/c0b561d864f8cd0427398726e21056c3
Just like in life, in crossword puzzles, it's not about having an endless supply of words, but making the most out of what you have - a lesson in frugality.
Looks more like a dp problem to me. Here is my long and ugly solution.
The main idea is, first find all the available spots where to put words. Then, find their length. Then, sort them by how many of each lengths there are. Start with the smallest numbers. If there is only one spot of length 5. The put the apppropriate word in that spot. Move to the next smallest number of words of that length, saving the possible configurations of the crossword that you found.
Then loop over each spot/word length. For each set word/spot lengths, try all possiblities, store all possible configurations at that stage. Repeat, by the end, only one possible solution works.
I think the functions ishstart/isvstart/findend/findspots and putword are reasonably nice. The function match can probably be writtend much better, in a recursive or nicer dp way.
Took me two days but fixed it by adding some randomnass in the solution