Generate Chess960 starting position: Difference between revisions

m
Line 1,142:
 
=={{header|J}}==
BuildThe simplest J approach for this task is to initially build a table of the starting positions. thenThen, for the task, we pick one position from the table at random. There are 40320 distinct permutations of 8 items and 5040 distinct permutations of these chess pieces and (as the task name points out) only 960 permutations which also satisfy the constraints on bishop and rook position, so little memory is needed to generate the table. Also, since the table is built at "compile time", execution is fast (though "compilation" is reasonably fast also).
 
<syntaxhighlight lang="j">row0=: u: 9812+2}.5|i.10
6,962

edits