/* Pi Day Sudoku 2008 in Picat. From Brainfreezepuzzles "Pi Day 2008" http://brainfreezepuzzles.com/main/piday2008.html The rules are in the PDF file: http://brainfreezepuzzles.com/main/files/pi_sudoku_2008.pdf """ Rules: Each row, column, and jigsaw region must contain exactly the first twelve digits of pi, including repeats: 3.14159265358. Notice that each region will contain two 1's, two 3's, three 5's, and no 7's. This puzzle is the most fun you'll ever have memorizing the first twelve digits of π! """ This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import util,cp. main => go. go => NumRegions = 12, % number of regions N = 12, % number of rows and columns % % Given hints % X = [ % 1 2 3 4 5 6 7 8 9 0 1 2 [3, _, _, 1, 5, 4, _, _, 1, _, 9, 5], % 1 [_, 1, _, _, 3, _, _, _, _, 1, 3, 6], % 2 [_, _, 4, _, _, 3, _, 8, _, _, 2, _], % 3 [5, _, _, 1, _, _, 9, 2, 5, _, _, 1], % 4 [_, 9, _, _, 5, _, _, 5, _, _, _, _], % 5 [5, 8, 1, _, _, 9, _, _, 3, _, 6, _], % 6 [_, 5, _, 8, _, _, 2, _, _, 5, 5, 3], % 7 [_, _, _, _, 5, _, _, 6, _, _, 1, _], % 8 [2, _, _, 5, 1, 5, _, _, 5, _, _, 9], % 9 [_, 6, _, _, 4, _, 1, _, _, 3, _, _], % 10 [1, 5, 1, _, _, _, _, 5, _, _, 5, _], % 11 [5, 5, _, 4, _, _, 3, 1, 6, _, _, 8] % 12 ], X :: 1..N, % Regions: % We code the cells as the region it belong Regions = [ % 1 2 3 4 5 6 7 8 9 0 1 2 [ 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3], % 1 [ 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3], % 2 [ 1, 1, 4, 4, 4, 4, 5, 5, 5, 5, 3, 3], % 3 [ 1, 1, 4, 4, 4, 4, 5, 5, 5, 5, 3, 3], % 4 [ 1, 1, 4, 4, 4, 4, 5, 5, 5, 5, 3, 3], % 5 [ 6, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10], % 6 [ 6, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10], % 7 [ 6, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10], % 8 [ 6, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10], % 9 [11,11,11, 7, 7, 8, 8, 9, 9,12,12,12], % 10 [11,11,11, 7, 7, 8, 8, 9, 9,12,12,12], % 11 [11,11,11,11,11,11,12,12,12,12,12,12] % 12 ], % occurences: 314159265358 % 1 2 3 4 5 6 7 8 9 Occ = [2,1,2,1,3,1,0,1,1], GCC = $[I-Occ[I] : I in 1..9], % GCC on rows and columns foreach(I in 1..N) global_cardinality([X[I,J] : J in 1..N], GCC), global_cardinality([X[J,I] : J in 1..N],GCC) end, % GCC on regions foreach(K in 1..NumRegions) global_cardinality([X[I,J] : I in 1..N, J in 1..N, Regions[I,J] == K], GCC) end, solve(X), foreach(Row in X) println(Row) end, nl, fail, nl.