Knight's tour: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 9,012: | Line 9,012: | ||
solution found in 64 tries (0.00s) |
solution found in 64 tries (0.00s) |
||
</pre> |
</pre> |
||
=={{header|Picat}}== |
|||
<lang Picat>import cp. |
|||
main => |
|||
N = 8, |
|||
A = new_array(N,N), |
|||
foreach (R in 1..N, C in 1..N) |
|||
Connected = [(R+1, C+2), |
|||
(R+1, C-2), |
|||
(R-1, C+2), |
|||
(R-1, C-2), |
|||
(R+2, C+1), |
|||
(R+2, C-1), |
|||
(R-2, C+1), |
|||
(R-2, C-1)], |
|||
A[R,C] :: [(R1-1)*N+C1 : (R1,C1) in Connected, R1 >= 1, R1 =< N, C1 >= 1, C1 =< N] |
|||
end, |
|||
V = vars(A), |
|||
circuit(V), |
|||
solve([ff],V), |
|||
OutputM = new_array(N,N), |
|||
fill_output_matrix(N,OutputM,V,1,1), |
|||
foreach (R in 1..N) |
|||
foreach (C in 1..N) |
|||
printf("%3d ", OutputM[R,C]) |
|||
end, |
|||
nl |
|||
end. |
|||
fill_output_matrix(N,OutputM,V,I,Count) => |
|||
if Count =< N*N then |
|||
R = (I-1) div N + 1, |
|||
C = (I-1) mod N + 1, |
|||
OutputM[R,C] = Count, |
|||
fill_output_matrix(N,OutputM,V,V[I],Count+1) |
|||
end. |
|||
</lang> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |