| 1 |
/*** |
| 2 |
!Test |
| 3 |
expected: |
| 4 |
- !Result |
| 5 |
solution: !Solution |
| 6 |
a: [1, 7, 1, 2, 6, 4, 2, 5, 3, 7, 4, 6, 3, 5] |
| 7 |
- !Result |
| 8 |
solution: !Solution |
| 9 |
a: [1, 7, 1, 2, 5, 6, 2, 3, 4, 7, 5, 3, 6, 4] |
| 10 |
- !Result |
| 11 |
solution: !Solution |
| 12 |
a: [2, 7, 4, 2, 3, 5, 6, 4, 3, 7, 1, 5, 1, 6] |
| 13 |
- !Result |
| 14 |
solution: !Solution |
| 15 |
a: [3, 6, 7, 1, 3, 1, 4, 5, 6, 2, 7, 4, 2, 5] |
| 16 |
- !Result |
| 17 |
solution: !Solution |
| 18 |
a: [2, 6, 7, 2, 1, 5, 1, 4, 6, 3, 7, 5, 4, 3] |
| 19 |
- !Result |
| 20 |
solution: !Solution |
| 21 |
a: [4, 1, 7, 1, 6, 4, 2, 5, 3, 2, 7, 6, 3, 5] |
| 22 |
- !Result |
| 23 |
solution: !Solution |
| 24 |
a: [2, 3, 7, 2, 6, 3, 5, 1, 4, 1, 7, 6, 5, 4] |
| 25 |
- !Result |
| 26 |
solution: !Solution |
| 27 |
a: [2, 4, 7, 2, 3, 6, 4, 5, 3, 1, 7, 1, 6, 5] |
| 28 |
- !Result |
| 29 |
solution: !Solution |
| 30 |
a: [3, 5, 7, 2, 3, 6, 2, 5, 4, 1, 7, 1, 6, 4] |
| 31 |
- !Result |
| 32 |
solution: !Solution |
| 33 |
a: [4, 6, 1, 7, 1, 4, 3, 5, 6, 2, 3, 7, 2, 5] |
| 34 |
- !Result |
| 35 |
solution: !Solution |
| 36 |
a: [1, 6, 1, 7, 2, 4, 5, 2, 6, 3, 4, 7, 5, 3] |
| 37 |
- !Result |
| 38 |
solution: !Solution |
| 39 |
a: [3, 4, 6, 7, 3, 2, 4, 5, 2, 6, 1, 7, 1, 5] |
| 40 |
- !Result |
| 41 |
solution: !Solution |
| 42 |
a: [1, 5, 1, 7, 3, 4, 6, 5, 3, 2, 4, 7, 2, 6] |
| 43 |
- !Result |
| 44 |
solution: !Solution |
| 45 |
a: [2, 6, 3, 2, 7, 4, 3, 5, 6, 1, 4, 1, 7, 5] |
| 46 |
- !Result |
| 47 |
solution: !Solution |
| 48 |
a: [2, 3, 6, 2, 7, 3, 4, 5, 1, 6, 1, 4, 7, 5] |
| 49 |
- !Result |
| 50 |
solution: !Solution |
| 51 |
a: [4, 1, 6, 1, 7, 4, 3, 5, 2, 6, 3, 2, 7, 5] |
| 52 |
- !Result |
| 53 |
solution: !Solution |
| 54 |
a: [1, 5, 1, 6, 7, 2, 4, 5, 2, 3, 6, 4, 7, 3] |
| 55 |
- !Result |
| 56 |
solution: !Solution |
| 57 |
a: [1, 4, 1, 6, 7, 3, 4, 5, 2, 3, 6, 2, 7, 5] |
| 58 |
- !Result |
| 59 |
solution: !Solution |
| 60 |
a: [1, 6, 1, 3, 5, 7, 4, 3, 6, 2, 5, 4, 2, 7] |
| 61 |
- !Result |
| 62 |
solution: !Solution |
| 63 |
a: [2, 6, 3, 2, 5, 7, 3, 4, 6, 1, 5, 1, 4, 7] |
| 64 |
- !Result |
| 65 |
solution: !Solution |
| 66 |
a: [5, 2, 6, 4, 2, 7, 5, 3, 4, 6, 1, 3, 1, 7] |
| 67 |
- !Result |
| 68 |
solution: !Solution |
| 69 |
a: [2, 5, 6, 2, 3, 7, 4, 5, 3, 6, 1, 4, 1, 7] |
| 70 |
- !Result |
| 71 |
solution: !Solution |
| 72 |
a: [5, 2, 4, 6, 2, 7, 5, 4, 3, 1, 6, 1, 3, 7] |
| 73 |
- !Result |
| 74 |
solution: !Solution |
| 75 |
a: [1, 5, 1, 6, 3, 7, 4, 5, 3, 2, 6, 4, 2, 7] |
| 76 |
- !Result |
| 77 |
solution: !Solution |
| 78 |
a: [1, 5, 1, 4, 6, 7, 3, 5, 4, 2, 3, 6, 2, 7] |
| 79 |
- !Result |
| 80 |
solution: !Solution |
| 81 |
a: [1, 4, 1, 5, 6, 7, 4, 2, 3, 5, 2, 6, 3, 7] |
| 82 |
***/ |
| 83 |
|
| 84 |
% vim: ft=zinc ts=4 sw=4 et |
| 85 |
% Ralph Becket <[email protected]> |
| 86 |
% Wed Feb 25 16:43:52 EST 2009 |
| 87 |
% |
| 88 |
% Langford's problem (see e.g., http://www.lclark.edu/~miller/langford.html) |
| 89 |
% ------------------ |
| 90 |
% |
| 91 |
% Arrange k sets of 1..n such that successive occurrences of any number, k, |
| 92 |
% are separated by k other numbers. |
| 93 |
|
| 94 |
% There should be 26 solutions to this problem. |
| 95 |
int: k = 2; |
| 96 |
int: n = 7; |
| 97 |
int: nk = n * k; |
| 98 |
|
| 99 |
array [1..nk] of var 1..n: a; % The sequence. |
| 100 |
array [1..n] of var 1..nk: Fst; % Fst[k] is position of first k. |
| 101 |
|
| 102 |
% Break some symmetry. |
| 103 |
% |
| 104 |
constraint a[1] <= a[nk]; |
| 105 |
|
| 106 |
% Prune some domains. |
| 107 |
% |
| 108 |
constraint |
| 109 |
forall ( i in 1..n ) ( Fst[i] <= nk - (k - 1) * (i + 1) ); |
| 110 |
|
| 111 |
% The nitty gritty. |
| 112 |
% |
| 113 |
constraint |
| 114 |
forall ( i in 1..n, j in 0..(k - 1) ) ( a[Fst[i] + j * (i + 1)] = i ); |
| 115 |
|
| 116 |
solve :: int_search(Fst, first_fail, indomain_min, complete) satisfy; |
| 117 |
|
| 118 |
output ["a = ", show(a), ";\n"]; |