% Find all solutions of 8 Queens on a chessboard, without any
% of them attacking each other.
%
% Solution after K. Helsgaun, Roskilde (DK).
%
begin integer array q,u,d (-17:17);
   procedure p(r,c,q,u,d); value q,u,d; short integer r,c;
                                     integer array q,u,d;
   if q(c)+u(r-c)+d(r+c) = 0 then begin
      q(c):= u(r-c):= d(r+c):= r;
      for c:= 1 step 1 until 8 do if r<8 then p(r+1,c,q,u,d) else begin
         outchar(char(q(c)+rank('A')-1)); outint(c,1);
         outchar(' '); if c = 8 then outimage;
      end;
   end;
   
   p(0,17,q,u,d);
   
end;