1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| private const M as integer = 4
private const N as integer = 5
private const showSolutions as boolean = false
private grid(m,n) as integer ' tableau à 2 dimensions
private solutions as integer = 0
public shared sub main ' démarrage de l'appli console
place(1)
console.writeline (solutions.tostring & " solutions")
end sub
public sub place (depth as integer)
if 2*(depth-1) = M*N Then
if showSolutions then
for x as integer = 0 to M-1
for y as ingeer = 0 to N-1
console.writeline(grid(x,y))
next
console.writeline("")
next
solutions+=1
end if
else
for x as integer = 0 to M-1
for y as ingeer = 0 to N-1
if grid(x,y) = 0 then
grid(x,y) = depth
if x+1<M and grid(x+1,y) = 0 then
grid(x+1,y) = depth
place(depth+1)
grid(x+1,y) = 0
end if
if (y+1 <N andalso grid(x,y+1) = 0 then
grid(x,y+1) = depth
place(depth+1)
grid(x,y+1) = 0
end if
grid(x,y = 0
return
next
next
end if |
Partager