b(I):-between(1,41,I).\x0d m:-b(I),b(J),f(I,J,8),J=41,nl,fail.\x0d f(I,J,N):-J<I,!,f(J,I,N);J>21,!,f(I,42-J,N);N>2,I>N,!,f(I-N,J-N,N-2);(I mod N=:=1;J mod N=:=1),!,write([]);write(' ').
Note that non-ascii characters in the above source code will be escaped (such as \x9f).