/* Kaos Sudoku in Picat. From Adrian Groza "Modelling Puzzles in First Order Logic" """ Puzzle 99. Kaos Sudoku Fill the cell with the numbers from 0 to size-1 of the puzzle. Each number can appear only once—in each cage, column, and row (Fig. 10.5). (taken from Kleber (2013)) """ Cages: [1,1,2,2,2] [1,3,2,2,4] [1,3,3,3,4] [1,5,5,3,4] [5,5,5,4,4] Hints: [3,_,_,_,1] [_,_,_,_,_] [_,_,_,_,_] [_,_,3,4,_] [2,_,_,_,_] Solution: [3,2,4,0,1] [1,0,2,3,4] [4,3,1,2,0] [0,1,3,4,2] [2,4,0,1,3] This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => puzzle(1,NumCages,Cages,X), println("Cages:"), foreach(Row in Cages) println(Row.to_list) end, nl, println("Hints:"), foreach(Row in X) println([V : R in Row, V = cond(nonvar(R),R,"_")]) end, N = Cages.len, X :: 0..N-1, foreach(I in 1..N) all_different([X[I,J] : J in 1..N]), all_different([X[J,I] : J in 1..N]), end, foreach(C in 1..NumCages) all_different([X[I,J] : I in 1..N, J in 1..N, Cages[I,J] == C]) end, solve(X.vars), println("\nSolution:"), foreach(Row in X) println(Row.to_list) end, nl, fail, nl. puzzle(1,NumCages,Cages,Hints) => NumCages = 5, Cages = {{1,1,2,2,2}, {1,3,2,2,4}, {1,3,3,3,4}, {1,5,5,3,4}, {5,5,5,4,4}}, Hints = {{3,_,_,_,1}, {_,_,_,_,_}, {_,_,_,_,_}, {_,_,3,4,_}, {2,_,_,_,_}}.