/* Pi Day Sudoku 2011 in Picat. From Brainfreezepuzzles "Pi Day 2011" http://brainfreezepuzzles.com/main/piday2011.html The rules are in the PDF file: http://brainfreezepuzzles.com/main/puzzles/Brainfreeze_PiDay2011.pdf """ Rules: This pie has 12 wedges. Fill in the grid so that the numbers 1-12 appear exactly once in each region of the pie. There are three types of regions in this pie, each containing 12 cells. They are: each of the six rings going all the way around the pie; each of the six pairs of opposite wedges; and each of the six adjacent pairs of wedges of the same color. """ 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 => M = 6, % number of cycles (rows) N = 12, % number of slices (wedges, columns) % The problem as a m x n matrix % We follow the clock numbering for the representation, % Column 1 is the one o'clock wedge, and then clockwise... % % Row 1 is the outer circle, row 2 the next, etc. X = [ % 1 2 3 4 5 6 7 8 9 0 1 2 [ _, _, _, _, 4, 9, _, _, _, _,11, 1], % 1 [12, _, _, _, 7, 6, 8, _, _, _, 9, 5], % 2 [ 9,10, _, _, _, _, 4,12, _, _, _, _], % 3 [ 3, 4, 2, _, _, _, 1, 6,11, _, _, _], % 4 [ _, _, 6,12, _, _, _, _, 1, 7, _, _], % 5 [ _, _, 9, 1, 5, _, _, _, 4, 2, 3, _] % 6 ], X :: 1..N, % all different of rows (circles) foreach(I in 1..M) all_different([X[I,J] : J in 1..N]) end, % all different on neighbour wedges foreach(J in 2..10, J mod 2 == 0) all_different([ X[I,J] : I in 1..M] ++ [ X[I,J+1] : I in 1..M]) end, % 1 <-> 12 all_different([ X[I,1] : I in 1..M] ++ [ X[I,12] : I in 1..M]), % all different on opposite wedges foreach(J in 1..M) all_different([ X[I,J] : I in 1..M] ++ [ X[I,J+M] : I in 1..M]) end, solve(X), foreach(Row in X) println(Row) end, fail, nl.