Algorithm X solves exact cover problem with trial and error method.
Program reads sequence of rows F, W1,..., Wn, where F is filter and W1,..., Wn is an instance of exact cover problem.
All rows have the same length d. Row F contains "-" and "+" signs.
Every row W1,..., Wn contains at least one row other than "_".
Program returns sequence of rows representing solutions of instance W1,..., Wn transformed by filter F by removing positions which have "_" in filter F.
Solution of instance W1,..., Wn is set Q ⊆ {1,..., n} represented by text R of length d. This text does not contain "_" sign and satisifies condition
∀ 1 ≤ i ≤ d ∃ j ∈ Q ((Wj)i = Ri ∧ ∀k ∈ Q∖{j} (Wk)i = _ )
Solutions are built out of rows W1,..., Wn according to their ordering. Given one solution, by trial and error we choose signs not colliding with previous choices.