Solve a Hidato puzzle: Difference between revisions

no edit summary
m (→‎{{header|Phix}}: syntax coloured)
No edit summary
Line 3,425:
solution found in 82 tries (0.02s)
</pre>
 
=={{header|Picat}}==
<lang Picat>import sat.
 
main =>
M = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, _,33,35, _, _, 0, 0, 0, 0},
{0, _, _,24,22, _, 0, 0, 0, 0},
{0, _, _, _,21, _, _, 0, 0, 0},
{0, _,26, _,13,40,11, 0, 0, 0},
{0,27, _, _, _, 9, _, 1, 0, 0},
{0, 0, 0, _, _,18, _, _, 0, 0},
{0, 0, 0, 0, 0, _, 7, _, _, 0},
{0, 0, 0, 0, 0, 0, 0, 5, _, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
MaxR = len(M),
MaxC = len(M[1]),
NZeros = len([1 : R in 1..MaxR, C in 1..MaxC, M[R,C] == 0]),
M :: 0..MaxR*MaxC-NZeros,
Vs = [{(R,C),1} : R in 1..MaxR, C in 1..MaxC, M[R,C] !== 0],
find_start(M,MaxR,MaxC,StartR,StartC),
Es = [{(R,C),(R1,C1),_} : R in 1..MaxR, C in 1..MaxC, M[R,C] !== 0,
neibs(M,MaxR,MaxC,R,C,Neibs),
(R1,C1) in [(StartR,StartC)|Neibs], M[R1,C1] !== 0],
hcp(Vs,Es),
foreach ({(R,C),(R1,C1),B} in Es)
B #/\ M[R1,C1] #!= 1 #=> M[R1,C1] #= M[R,C]+1
end,
solve(M),
foreach (R in 1..MaxR)
foreach (C in 1..MaxC)
if M[R,C] == 0 then
printf("%4c", '.')
else
printf("%4d", M[R,C])
end
end,
nl
end.
 
find_start(M,MaxR,MaxC,StartR,StartC) =>
between(1,MaxR,StartR),
between(1,MaxC,StartC),
M[StartR,StartC] == 1,!.
neibs(M,MaxR,MaxC,R,C,Neibs) =>
Neibs = [(R1,C1) : Dr in -1..1, Dc in -1..1, R1 = R+Dr, C1 = C+Dc,
R1 >= 1, R1 =< MaxR, C1 >= 1, C1 =< MaxC,
(R1,C1) != (R,C), M[R1,C1] !== 0].
</lang>
{{out}}
<pre>
. . . . . . . . . .
. 32 33 35 36 37 . . . .
. 31 34 24 22 38 . . . .
. 30 25 23 21 12 39 . . .
. 29 26 20 13 40 11 . . .
. 27 28 14 19 9 10 1 . .
. . . 15 16 18 8 2 . .
. . . . . 17 7 6 3 .
. . . . . . . 5 4 .
. . . . . . . . . .
</pre>
 
 
=={{header|PicoLisp}}==
Anonymous user