/* Black Hole Patience Game in Picat. Port/Inspiration of SICStus Prolog model library/clpfd/examples/black_hole.pl """ File : black_hole.pl Maintainer : Mats Carlsson Updated : November 2011 Purpose : Solving the Black Hole Patience Game Search in the Patience Game 'Black Hole'. Ian Gent, Christopher Jefferson, Ines Lynce, Ian Miguel, Peter Nightingale, Barbara Smith and Armagan Tarim. AI Communications (20), pp. 211-226, 2007. An earlier version appeared as Report CPPod-10-2005. """ Solution from SICStus model: [1,2,14,15,16,17,18,19,20,8,9,10,11,36,22,34,33,45,31,30,3,28,29,41,27,39,40,52,12,24,38,37,23,35,47,7,6,5,4,42,43,44,32,46,21,48,49,50,25,13,51,26] This model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import sat. import cp. main => go. go ?=> black_hole, fail, nl. go => true. black_hole :- Card = new_list(52), Card :: 1..52, Pos = new_list(52), Pos :: 1..52, % Ace of Spades is first card Card = [1|_], all_different(Card), % hakank: faster all_different(Pos), % hakank: faster % Consecutive cards match neighbors(Table1), % hakank: Translate to list of arrays Table = [{T1,T2} : [T1,T2] in Table1], % Ensure that the neighbours in Cards are in the Neighbours table Tuples = zip(Card[1..51],Card[2..52]), table_in(Tuples,Table), % Link cards and positions assignment(Card, Pos), % A card must be played before the one under it. layout(Layout), foreach(LayoutPos in Layout) increasing([Pos[I] : I in LayoutPos]) end, solve($[ffd,split], Card ++ Pos), printf("Card sequence: %w\n", Card). neighbors([[ 1, 2], [ 1, 13], [ 1, 15], [ 1, 26], [ 1, 28], [ 1, 39], [ 1, 41], [ 1, 52], [ 2, 1], [ 2, 3], [ 2, 14], [ 2, 16], [ 2, 27], [ 2, 29], [ 2, 40], [ 2, 42], [ 3, 2], [ 3, 4], [ 3, 15], [ 3, 17], [ 3, 28], [ 3, 30], [ 3, 41], [ 3, 43], [ 4, 3], [ 4, 5], [ 4, 16], [ 4, 18], [ 4, 29], [ 4, 31], [ 4, 42], [ 4, 44], [ 5, 4], [ 5, 6], [ 5, 17], [ 5, 19], [ 5, 30], [ 5, 32], [ 5, 43], [ 5, 45], [ 6, 5], [ 6, 7], [ 6, 18], [ 6, 20], [ 6, 31], [ 6, 33], [ 6, 44], [ 6, 46], [ 7, 6], [ 7, 8], [ 7, 19], [ 7, 21], [ 7, 32], [ 7, 34], [ 7, 45], [ 7, 47], [ 8, 7], [ 8, 9], [ 8, 20], [ 8, 22], [ 8, 33], [ 8, 35], [ 8, 46], [ 8, 48], [ 9, 8], [ 9, 10], [ 9, 21], [ 9, 23], [ 9, 34], [ 9, 36], [ 9, 47], [ 9, 49], [10, 9], [10, 11], [10, 22], [10, 24], [10, 35], [10, 37], [10, 48], [10, 50], [11, 10], [11, 12], [11, 23], [11, 25], [11, 36], [11, 38], [11, 49], [11, 51], [12, 11], [12, 13], [12, 24], [12, 26], [12, 37], [12, 39], [12, 50], [12, 52], [13, 1], [13, 12], [13, 14], [13, 25], [13, 27], [13, 38], [13, 40], [13, 51], [14, 2], [14, 13], [14, 15], [14, 26], [14, 28], [14, 39], [14, 41], [14, 52], [15, 1], [15, 3], [15, 14], [15, 16], [15, 27], [15, 29], [15, 40], [15, 42], [16, 2], [16, 4], [16, 15], [16, 17], [16, 28], [16, 30], [16, 41], [16, 43], [17, 3], [17, 5], [17, 16], [17, 18], [17, 29], [17, 31], [17, 42], [17, 44], [18, 4], [18, 6], [18, 17], [18, 19], [18, 30], [18, 32], [18, 43], [18, 45], [19, 5], [19, 7], [19, 18], [19, 20], [19, 31], [19, 33], [19, 44], [19, 46], [20, 6], [20, 8], [20, 19], [20, 21], [20, 32], [20, 34], [20, 45], [20, 47], [21, 7], [21, 9], [21, 20], [21, 22], [21, 33], [21, 35], [21, 46], [21, 48], [22, 8], [22, 10], [22, 21], [22, 23], [22, 34], [22, 36], [22, 47], [22, 49], [23, 9], [23, 11], [23, 22], [23, 24], [23, 35], [23, 37], [23, 48], [23, 50], [24, 10], [24, 12], [24, 23], [24, 25], [24, 36], [24, 38], [24, 49], [24, 51], [25, 11], [25, 13], [25, 24], [25, 26], [25, 37], [25, 39], [25, 50], [25, 52], [26, 1], [26, 12], [26, 14], [26, 25], [26, 27], [26, 38], [26, 40], [26, 51], [27, 2], [27, 13], [27, 15], [27, 26], [27, 28], [27, 39], [27, 41], [27, 52], [28, 1], [28, 3], [28, 14], [28, 16], [28, 27], [28, 29], [28, 40], [28, 42], [29, 2], [29, 4], [29, 15], [29, 17], [29, 28], [29, 30], [29, 41], [29, 43], [30, 3], [30, 5], [30, 16], [30, 18], [30, 29], [30, 31], [30, 42], [30, 44], [31, 4], [31, 6], [31, 17], [31, 19], [31, 30], [31, 32], [31, 43], [31, 45], [32, 5], [32, 7], [32, 18], [32, 20], [32, 31], [32, 33], [32, 44], [32, 46], [33, 6], [33, 8], [33, 19], [33, 21], [33, 32], [33, 34], [33, 45], [33, 47], [34, 7], [34, 9], [34, 20], [34, 22], [34, 33], [34, 35], [34, 46], [34, 48], [35, 8], [35, 10], [35, 21], [35, 23], [35, 34], [35, 36], [35, 47], [35, 49], [36, 9], [36, 11], [36, 22], [36, 24], [36, 35], [36, 37], [36, 48], [36, 50], [37, 10], [37, 12], [37, 23], [37, 25], [37, 36], [37, 38], [37, 49], [37, 51], [38, 11], [38, 13], [38, 24], [38, 26], [38, 37], [38, 39], [38, 50], [38, 52], [39, 1], [39, 12], [39, 14], [39, 25], [39, 27], [39, 38], [39, 40], [39, 51], [40, 2], [40, 13], [40, 15], [40, 26], [40, 28], [40, 39], [40, 41], [40, 52], [41, 1], [41, 3], [41, 14], [41, 16], [41, 27], [41, 29], [41, 40], [41, 42], [42, 2], [42, 4], [42, 15], [42, 17], [42, 28], [42, 30], [42, 41], [42, 43], [43, 3], [43, 5], [43, 16], [43, 18], [43, 29], [43, 31], [43, 42], [43, 44], [44, 4], [44, 6], [44, 17], [44, 19], [44, 30], [44, 32], [44, 43], [44, 45], [45, 5], [45, 7], [45, 18], [45, 20], [45, 31], [45, 33], [45, 44], [45, 46], [46, 6], [46, 8], [46, 19], [46, 21], [46, 32], [46, 34], [46, 45], [46, 47], [47, 7], [47, 9], [47, 20], [47, 22], [47, 33], [47, 35], [47, 46], [47, 48], [48, 8], [48, 10], [48, 21], [48, 23], [48, 34], [48, 36], [48, 47], [48, 49], [49, 9], [49, 11], [49, 22], [49, 24], [49, 35], [49, 37], [49, 48], [49, 50], [50, 10], [50, 12], [50, 23], [50, 25], [50, 36], [50, 38], [50, 49], [50, 51], [51, 11], [51, 13], [51, 24], [51, 26], [51, 37], [51, 39], [51, 50], [51, 52], [52, 1], [52, 12], [52, 14], [52, 25], [52, 27], [52, 38], [52, 40], [52, 51]]). layout([[20, 39, 6], [34, 31, 32], [15, 33, 38], [40, 4, 43], [16, 37, 7], [2, 18, 19], [8, 41, 47], [35, 25, 51], [28, 5, 21], [45, 24, 23], [9, 3, 46], [27, 52, 26], [14, 30, 44], [36, 12, 49], [10, 29, 42], [48, 50, 13], [17, 11, 22]]).