6

« Last post by **jsalai ** on* July 28, 2021, 23:03:15* »
Here an adaptation of recursive c-code, that finds ALL solutions for specified boards.

In this example shown the 3x10 board with 6096 solutions, and 960 "closed" solutions.

Closed means that the knight may close the cycle jumping to the initial field.

It finds all soutions of any board, but beware, for some boards (eg normal 8x8) it takes a kind of an eternity.

Of course, the numbers are not exact, as there are lots of solutions which are symmetrical transformations of some previous. I don't want to perform such analyses.

I could make loops for only half of hor and vert, but for square boards it would not suffice, bcs eg:

a1-b3 could produce a symetry to a1-c2 so I left them all shown...

As the task is anyway useless, I don't expect anyone to try to make an improvement...

`x0=3:y0=10:mm=x0*y0:zz=0:color 15,0`

xm=[2,1,-1,-2,-2,-1,1,2]:ym=[1,2,2,1,-1,-2,-2,-1]

open x0+"x"+y0+".txt" for output as #1

for i=0 to x0-1

for j=0 to y0-1

dim s(x0-1,y0-1)

sol(i,j,1,s)

next

next

?"Done":close #1:pause

end

sub sol(x,y,m,@s)

local k,xn,yn

s(x,y)=m

if m=mm

c0=(1 in s)-1:cm=(mm in s)-1:p0=c0\y0:q0=c0%y0:pm=cm\y0:qm=cm%y0

ss=iff(((abs(pm-p0)=1) && (abs(qm-q0)=2)) || ((abs(pm-p0)=2) && (abs(qm-q0)=1)),"closed","")

zz++:?zz;s;ss:?#1,zz;s;ss

s(x,y)=0

exit sub

fi

for k=0 to 7

xn=x+xm(k):yn=y+ym(k)

if xn>=0 && xn<x0 && yn>=0 && yn<y0 && !s(xn,yn)

sol(xn,yn,m+1,s)

fi

next

s(x,y)=0

end sub