/** * Homework 9. * * #2. Construct a Sudograph solver. * * Sudograph is a generalization of the popular sudoku puzzles. * * A single puzzle specifies * a list of nodes, represented by logical variables, * a list of constraints, represented as lists of those same local variables, * a list of colors, which are atomic (atoms or numbers). * * The objective is to find a solution of the puzzle, which is defined to be * an assignment of a color to each node, such that no two nodes in any * constraint are assigned the same color. * * You should write a predicate called sudograph( Nodes, Constraints, Colors ) to achieve this goal. * Be sure to give it exactly this name or the test code below will not work. The names of the arguments * do not matter, just the name of the predicate, i.e., "sudograph". */ /* Here is some code that will help make testing your predicate easier. */ testSudoGraph(1) :- Nodes = [A, B, C, D, E, F, G], Constraints = [[A, B, C], [B, C, D], [C, D, E], [D, E, F], [E, F, G], [G, A, B]], Colors = [red, blue, green, yellow], testSudoGraph(Nodes, Constraints, Colors). /* Sample output: ?- testSudoGraph(1). Colors: [red, blue, green, yellow] Nodes: [red, blue, green, red, blue, green, yellow] Constraints: [red, blue, green] [blue, green, red] [green, red, blue] [red, blue, green] [blue, green, yellow] [yellow, red, blue] */ testSudoGraph(Nodes, Constraints, Colors) :- sudograph( Nodes, Constraints, Colors), write('Colors: '), write(Colors), nl, write('Nodes: '), write(Nodes), nl, write('Constraints: '), nl, showConstraints(Constraints). showConstraints([]). showConstraints([Constraint | Constraints]) :- write(' '), write(Constraint), nl, showConstraints(Constraints).