Search code examples
prologcrossword

Generalized solver for crossword puzzle in Prolog


Here is the problem and a specialized version of solution. Learning Prolog: solving a crossword scheme

What I am looking for is a generalized solver using the same model. I think I need to generate those variable names on the fly but I don't know how. I am using swi-prolog.

By generalized solver, I mean a solver capable of solving N by N crossword puzzle, N is NOT predefined.


Solution

  • In Prolog, there are lots of amusing ways to generate variable names on the fly. Here's a pretty simple one:

    ?- length(X, 3).
    X = [_G945, _G948, _G951].
    

    This works because length/2 is implemented to traverse a list, but it doesn't actually establish bindings on the things in the list. You can do something similar with any other data structure, traversing the structure without examining the values contained within it. Some Prolog books refer to this as "data structures with holes."