n_queens = cluster is solve rep = null own hist: array[int] := array[int]$[] own solutions: array[string] := array[string]$[] attack = proc (i,j,col: int) returns (bool) return(hist[j]=i | int$abs(hist[j]-i)=col-j) end attack cur_solution = proc () n: int := array[int]$size(hist) ss: stream := stream$create_output() for i: int in int$from_to(0,n-1) do for j: int in int$from_to(0,n-1) do if j=hist[i] then stream$putc(ss, 'Q') elseif (i+j)//2 = 1 then stream$putc(ss, ' ') else stream$putc(ss, '.') end end stream$putc(ss, '\n') end array[string]$addh(solutions, stream$get_contents(ss)) end cur_solution solve_rec = proc (col: int) n: int := array[int]$size(hist) if col=n then cur_solution() return end for i: int in int$from_to(0,n-1) do j: int := 0 while j