# Find the Chess960 starting positions from its integer ID

Chess960, a.k.a. Fisher random chess, is a variation of the game of chess.

In classic chess the starting positions are always the same. In chess960 they vary.

Before each game of chess960 one random number from 0 to 959 is drawn. Both players then arrange their pieces in the same way according to this number from a lookup table:

There are 960 valid starting positions (SP). They are indexed from 0 to 959 and often prefixed with "SP-" or "SP". The starting position of classic chess for instance is SP-518 that is RNBQKBNR or ♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜

The challenge

Create a program or a function that when given an integer from 0 to 959 it prints or returns the starting position as a string of length 8 consisting of the letters R, N, B, Q, K. Two R (rooks), two N (kNights), two B (bishops). Then one Q (queen) and one K (king). Ignore the pawns as they are placed just as in classic chess.

Various methods exists to calculate the starting positions from 0-959. Some might be undiscovered? A few simple methods are described at: https://en.wikipedia.org/wiki/Fischer_random_chess_numbering_scheme

The array of valid starting positions are:

 0  BBQNNRKR   1 BQNBNRKR   2 BQNNRBKR   3 BQNNRKRB   4 QBBNNRKR   5 QNBBNRKR   6 QNBNRBKR   7 QNBNRKRB   8 QBNNBRKR   9 QNNBBRKR
10  QNNRBBKR  11 QNNRBKRB  12 QBNNRKBR  13 QNNBRKBR  14 QNNRKBBR  15 QNNRKRBB  16 BBNQNRKR  17 BNQBNRKR  18 BNQNRBKR  19 BNQNRKRB
20  NBBQNRKR  21 NQBBNRKR  22 NQBNRBKR  23 NQBNRKRB  24 NBQNBRKR  25 NQNBBRKR  26 NQNRBBKR  27 NQNRBKRB  28 NBQNRKBR  29 NQNBRKBR
30  NQNRKBBR  31 NQNRKRBB  32 BBNNQRKR  33 BNNBQRKR  34 BNNQRBKR  35 BNNQRKRB  36 NBBNQRKR  37 NNBBQRKR  38 NNBQRBKR  39 NNBQRKRB
40  NBNQBRKR  41 NNQBBRKR  42 NNQRBBKR  43 NNQRBKRB  44 NBNQRKBR  45 NNQBRKBR  46 NNQRKBBR  47 NNQRKRBB  48 BBNNRQKR  49 BNNBRQKR
50  BNNRQBKR  51 BNNRQKRB  52 NBBNRQKR  53 NNBBRQKR  54 NNBRQBKR  55 NNBRQKRB  56 NBNRBQKR  57 NNRBBQKR  58 NNRQBBKR  59 NNRQBKRB
60  NBNRQKBR  61 NNRBQKBR  62 NNRQKBBR  63 NNRQKRBB  64 BBNNRKQR  65 BNNBRKQR  66 BNNRKBQR  67 BNNRKQRB  68 NBBNRKQR  69 NNBBRKQR
70  NNBRKBQR  71 NNBRKQRB  72 NBNRBKQR  73 NNRBBKQR  74 NNRKBBQR  75 NNRKBQRB  76 NBNRKQBR  77 NNRBKQBR  78 NNRKQBBR  79 NNRKQRBB
80  BBNNRKRQ  81 BNNBRKRQ  82 BNNRKBRQ  83 BNNRKRQB  84 NBBNRKRQ  85 NNBBRKRQ  86 NNBRKBRQ  87 NNBRKRQB  88 NBNRBKRQ  89 NNRBBKRQ
90  NNRKBBRQ  91 NNRKBRQB  92 NBNRKRBQ  93 NNRBKRBQ  94 NNRKRBBQ  95 NNRKRQBB  96 BBQNRNKR  97 BQNBRNKR  98 BQNRNBKR  99 BQNRNKRB
100 QBBNRNKR 101 QNBBRNKR 102 QNBRNBKR 103 QNBRNKRB 104 QBNRBNKR 105 QNRBBNKR 106 QNRNBBKR 107 QNRNBKRB 108 QBNRNKBR 109 QNRBNKBR
110 QNRNKBBR 111 QNRNKRBB 112 BBNQRNKR 113 BNQBRNKR 114 BNQRNBKR 115 BNQRNKRB 116 NBBQRNKR 117 NQBBRNKR 118 NQBRNBKR 119 NQBRNKRB
120 NBQRBNKR 121 NQRBBNKR 122 NQRNBBKR 123 NQRNBKRB 124 NBQRNKBR 125 NQRBNKBR 126 NQRNKBBR 127 NQRNKRBB 128 BBNRQNKR 129 BNRBQNKR
130 BNRQNBKR 131 BNRQNKRB 132 NBBRQNKR 133 NRBBQNKR 134 NRBQNBKR 135 NRBQNKRB 136 NBRQBNKR 137 NRQBBNKR 138 NRQNBBKR 139 NRQNBKRB
140 NBRQNKBR 141 NRQBNKBR 142 NRQNKBBR 143 NRQNKRBB 144 BBNRNQKR 145 BNRBNQKR 146 BNRNQBKR 147 BNRNQKRB 148 NBBRNQKR 149 NRBBNQKR
150 NRBNQBKR 151 NRBNQKRB 152 NBRNBQKR 153 NRNBBQKR 154 NRNQBBKR 155 NRNQBKRB 156 NBRNQKBR 157 NRNBQKBR 158 NRNQKBBR 159 NRNQKRBB
160 BBNRNKQR 161 BNRBNKQR 162 BNRNKBQR 163 BNRNKQRB 164 NBBRNKQR 165 NRBBNKQR 166 NRBNKBQR 167 NRBNKQRB 168 NBRNBKQR 169 NRNBBKQR
170 NRNKBBQR 171 NRNKBQRB 172 NBRNKQBR 173 NRNBKQBR 174 NRNKQBBR 175 NRNKQRBB 176 BBNRNKRQ 177 BNRBNKRQ 178 BNRNKBRQ 179 BNRNKRQB
180 NBBRNKRQ 181 NRBBNKRQ 182 NRBNKBRQ 183 NRBNKRQB 184 NBRNBKRQ 185 NRNBBKRQ 186 NRNKBBRQ 187 NRNKBRQB 188 NBRNKRBQ 189 NRNBKRBQ
190 NRNKRBBQ 191 NRNKRQBB 192 BBQNRKNR 193 BQNBRKNR 194 BQNRKBNR 195 BQNRKNRB 196 QBBNRKNR 197 QNBBRKNR 198 QNBRKBNR 199 QNBRKNRB
200 QBNRBKNR 201 QNRBBKNR 202 QNRKBBNR 203 QNRKBNRB 204 QBNRKNBR 205 QNRBKNBR 206 QNRKNBBR 207 QNRKNRBB 208 BBNQRKNR 209 BNQBRKNR
210 BNQRKBNR 211 BNQRKNRB 212 NBBQRKNR 213 NQBBRKNR 214 NQBRKBNR 215 NQBRKNRB 216 NBQRBKNR 217 NQRBBKNR 218 NQRKBBNR 219 NQRKBNRB
220 NBQRKNBR 221 NQRBKNBR 222 NQRKNBBR 223 NQRKNRBB 224 BBNRQKNR 225 BNRBQKNR 226 BNRQKBNR 227 BNRQKNRB 228 NBBRQKNR 229 NRBBQKNR
230 NRBQKBNR 231 NRBQKNRB 232 NBRQBKNR 233 NRQBBKNR 234 NRQKBBNR 235 NRQKBNRB 236 NBRQKNBR 237 NRQBKNBR 238 NRQKNBBR 239 NRQKNRBB
240 BBNRKQNR 241 BNRBKQNR 242 BNRKQBNR 243 BNRKQNRB 244 NBBRKQNR 245 NRBBKQNR 246 NRBKQBNR 247 NRBKQNRB 248 NBRKBQNR 249 NRKBBQNR
250 NRKQBBNR 251 NRKQBNRB 252 NBRKQNBR 253 NRKBQNBR 254 NRKQNBBR 255 NRKQNRBB 256 BBNRKNQR 257 BNRBKNQR 258 BNRKNBQR 259 BNRKNQRB
260 NBBRKNQR 261 NRBBKNQR 262 NRBKNBQR 263 NRBKNQRB 264 NBRKBNQR 265 NRKBBNQR 266 NRKNBBQR 267 NRKNBQRB 268 NBRKNQBR 269 NRKBNQBR
270 NRKNQBBR 271 NRKNQRBB 272 BBNRKNRQ 273 BNRBKNRQ 274 BNRKNBRQ 275 BNRKNRQB 276 NBBRKNRQ 277 NRBBKNRQ 278 NRBKNBRQ 279 NRBKNRQB
280 NBRKBNRQ 281 NRKBBNRQ 282 NRKNBBRQ 283 NRKNBRQB 284 NBRKNRBQ 285 NRKBNRBQ 286 NRKNRBBQ 287 NRKNRQBB 288 BBQNRKRN 289 BQNBRKRN
290 BQNRKBRN 291 BQNRKRNB 292 QBBNRKRN 293 QNBBRKRN 294 QNBRKBRN 295 QNBRKRNB 296 QBNRBKRN 297 QNRBBKRN 298 QNRKBBRN 299 QNRKBRNB
300 QBNRKRBN 301 QNRBKRBN 302 QNRKRBBN 303 QNRKRNBB 304 BBNQRKRN 305 BNQBRKRN 306 BNQRKBRN 307 BNQRKRNB 308 NBBQRKRN 309 NQBBRKRN
310 NQBRKBRN 311 NQBRKRNB 312 NBQRBKRN 313 NQRBBKRN 314 NQRKBBRN 315 NQRKBRNB 316 NBQRKRBN 317 NQRBKRBN 318 NQRKRBBN 319 NQRKRNBB
320 BBNRQKRN 321 BNRBQKRN 322 BNRQKBRN 323 BNRQKRNB 324 NBBRQKRN 325 NRBBQKRN 326 NRBQKBRN 327 NRBQKRNB 328 NBRQBKRN 329 NRQBBKRN
330 NRQKBBRN 331 NRQKBRNB 332 NBRQKRBN 333 NRQBKRBN 334 NRQKRBBN 335 NRQKRNBB 336 BBNRKQRN 337 BNRBKQRN 338 BNRKQBRN 339 BNRKQRNB
340 NBBRKQRN 341 NRBBKQRN 342 NRBKQBRN 343 NRBKQRNB 344 NBRKBQRN 345 NRKBBQRN 346 NRKQBBRN 347 NRKQBRNB 348 NBRKQRBN 349 NRKBQRBN
350 NRKQRBBN 351 NRKQRNBB 352 BBNRKRQN 353 BNRBKRQN 354 BNRKRBQN 355 BNRKRQNB 356 NBBRKRQN 357 NRBBKRQN 358 NRBKRBQN 359 NRBKRQNB
360 NBRKBRQN 361 NRKBBRQN 362 NRKRBBQN 363 NRKRBQNB 364 NBRKRQBN 365 NRKBRQBN 366 NRKRQBBN 367 NRKRQNBB 368 BBNRKRNQ 369 BNRBKRNQ
370 BNRKRBNQ 371 BNRKRNQB 372 NBBRKRNQ 373 NRBBKRNQ 374 NRBKRBNQ 375 NRBKRNQB 376 NBRKBRNQ 377 NRKBBRNQ 378 NRKRBBNQ 379 NRKRBNQB
380 NBRKRNBQ 381 NRKBRNBQ 382 NRKRNBBQ 383 NRKRNQBB 384 BBQRNNKR 385 BQRBNNKR 386 BQRNNBKR 387 BQRNNKRB 388 QBBRNNKR 389 QRBBNNKR
390 QRBNNBKR 391 QRBNNKRB 392 QBRNBNKR 393 QRNBBNKR 394 QRNNBBKR 395 QRNNBKRB 396 QBRNNKBR 397 QRNBNKBR 398 QRNNKBBR 399 QRNNKRBB
400 BBRQNNKR 401 BRQBNNKR 402 BRQNNBKR 403 BRQNNKRB 404 RBBQNNKR 405 RQBBNNKR 406 RQBNNBKR 407 RQBNNKRB 408 RBQNBNKR 409 RQNBBNKR
410 RQNNBBKR 411 RQNNBKRB 412 RBQNNKBR 413 RQNBNKBR 414 RQNNKBBR 415 RQNNKRBB 416 BBRNQNKR 417 BRNBQNKR 418 BRNQNBKR 419 BRNQNKRB
420 RBBNQNKR 421 RNBBQNKR 422 RNBQNBKR 423 RNBQNKRB 424 RBNQBNKR 425 RNQBBNKR 426 RNQNBBKR 427 RNQNBKRB 428 RBNQNKBR 429 RNQBNKBR
430 RNQNKBBR 431 RNQNKRBB 432 BBRNNQKR 433 BRNBNQKR 434 BRNNQBKR 435 BRNNQKRB 436 RBBNNQKR 437 RNBBNQKR 438 RNBNQBKR 439 RNBNQKRB
440 RBNNBQKR 441 RNNBBQKR 442 RNNQBBKR 443 RNNQBKRB 444 RBNNQKBR 445 RNNBQKBR 446 RNNQKBBR 447 RNNQKRBB 448 BBRNNKQR 449 BRNBNKQR
450 BRNNKBQR 451 BRNNKQRB 452 RBBNNKQR 453 RNBBNKQR 454 RNBNKBQR 455 RNBNKQRB 456 RBNNBKQR 457 RNNBBKQR 458 RNNKBBQR 459 RNNKBQRB
460 RBNNKQBR 461 RNNBKQBR 462 RNNKQBBR 463 RNNKQRBB 464 BBRNNKRQ 465 BRNBNKRQ 466 BRNNKBRQ 467 BRNNKRQB 468 RBBNNKRQ 469 RNBBNKRQ
470 RNBNKBRQ 471 RNBNKRQB 472 RBNNBKRQ 473 RNNBBKRQ 474 RNNKBBRQ 475 RNNKBRQB 476 RBNNKRBQ 477 RNNBKRBQ 478 RNNKRBBQ 479 RNNKRQBB
480 BBQRNKNR 481 BQRBNKNR 482 BQRNKBNR 483 BQRNKNRB 484 QBBRNKNR 485 QRBBNKNR 486 QRBNKBNR 487 QRBNKNRB 488 QBRNBKNR 489 QRNBBKNR
490 QRNKBBNR 491 QRNKBNRB 492 QBRNKNBR 493 QRNBKNBR 494 QRNKNBBR 495 QRNKNRBB 496 BBRQNKNR 497 BRQBNKNR 498 BRQNKBNR 499 BRQNKNRB
500 RBBQNKNR 501 RQBBNKNR 502 RQBNKBNR 503 RQBNKNRB 504 RBQNBKNR 505 RQNBBKNR 506 RQNKBBNR 507 RQNKBNRB 508 RBQNKNBR 509 RQNBKNBR
510 RQNKNBBR 511 RQNKNRBB 512 BBRNQKNR 513 BRNBQKNR 514 BRNQKBNR 515 BRNQKNRB 516 RBBNQKNR 517 RNBBQKNR 518 RNBQKBNR 519 RNBQKNRB
520 RBNQBKNR 521 RNQBBKNR 522 RNQKBBNR 523 RNQKBNRB 524 RBNQKNBR 525 RNQBKNBR 526 RNQKNBBR 527 RNQKNRBB 528 BBRNKQNR 529 BRNBKQNR
530 BRNKQBNR 531 BRNKQNRB 532 RBBNKQNR 533 RNBBKQNR 534 RNBKQBNR 535 RNBKQNRB 536 RBNKBQNR 537 RNKBBQNR 538 RNKQBBNR 539 RNKQBNRB
540 RBNKQNBR 541 RNKBQNBR 542 RNKQNBBR 543 RNKQNRBB 544 BBRNKNQR 545 BRNBKNQR 546 BRNKNBQR 547 BRNKNQRB 548 RBBNKNQR 549 RNBBKNQR
550 RNBKNBQR 551 RNBKNQRB 552 RBNKBNQR 553 RNKBBNQR 554 RNKNBBQR 555 RNKNBQRB 556 RBNKNQBR 557 RNKBNQBR 558 RNKNQBBR 559 RNKNQRBB
560 BBRNKNRQ 561 BRNBKNRQ 562 BRNKNBRQ 563 BRNKNRQB 564 RBBNKNRQ 565 RNBBKNRQ 566 RNBKNBRQ 567 RNBKNRQB 568 RBNKBNRQ 569 RNKBBNRQ
570 RNKNBBRQ 571 RNKNBRQB 572 RBNKNRBQ 573 RNKBNRBQ 574 RNKNRBBQ 575 RNKNRQBB 576 BBQRNKRN 577 BQRBNKRN 578 BQRNKBRN 579 BQRNKRNB
580 QBBRNKRN 581 QRBBNKRN 582 QRBNKBRN 583 QRBNKRNB 584 QBRNBKRN 585 QRNBBKRN 586 QRNKBBRN 587 QRNKBRNB 588 QBRNKRBN 589 QRNBKRBN
590 QRNKRBBN 591 QRNKRNBB 592 BBRQNKRN 593 BRQBNKRN 594 BRQNKBRN 595 BRQNKRNB 596 RBBQNKRN 597 RQBBNKRN 598 RQBNKBRN 599 RQBNKRNB
600 RBQNBKRN 601 RQNBBKRN 602 RQNKBBRN 603 RQNKBRNB 604 RBQNKRBN 605 RQNBKRBN 606 RQNKRBBN 607 RQNKRNBB 608 BBRNQKRN 609 BRNBQKRN
610 BRNQKBRN 611 BRNQKRNB 612 RBBNQKRN 613 RNBBQKRN 614 RNBQKBRN 615 RNBQKRNB 616 RBNQBKRN 617 RNQBBKRN 618 RNQKBBRN 619 RNQKBRNB
620 RBNQKRBN 621 RNQBKRBN 622 RNQKRBBN 623 RNQKRNBB 624 BBRNKQRN 625 BRNBKQRN 626 BRNKQBRN 627 BRNKQRNB 628 RBBNKQRN 629 RNBBKQRN
630 RNBKQBRN 631 RNBKQRNB 632 RBNKBQRN 633 RNKBBQRN 634 RNKQBBRN 635 RNKQBRNB 636 RBNKQRBN 637 RNKBQRBN 638 RNKQRBBN 639 RNKQRNBB
640 BBRNKRQN 641 BRNBKRQN 642 BRNKRBQN 643 BRNKRQNB 644 RBBNKRQN 645 RNBBKRQN 646 RNBKRBQN 647 RNBKRQNB 648 RBNKBRQN 649 RNKBBRQN
650 RNKRBBQN 651 RNKRBQNB 652 RBNKRQBN 653 RNKBRQBN 654 RNKRQBBN 655 RNKRQNBB 656 BBRNKRNQ 657 BRNBKRNQ 658 BRNKRBNQ 659 BRNKRNQB
660 RBBNKRNQ 661 RNBBKRNQ 662 RNBKRBNQ 663 RNBKRNQB 664 RBNKBRNQ 665 RNKBBRNQ 666 RNKRBBNQ 667 RNKRBNQB 668 RBNKRNBQ 669 RNKBRNBQ
670 RNKRNBBQ 671 RNKRNQBB 672 BBQRKNNR 673 BQRBKNNR 674 BQRKNBNR 675 BQRKNNRB 676 QBBRKNNR 677 QRBBKNNR 678 QRBKNBNR 679 QRBKNNRB
680 QBRKBNNR 681 QRKBBNNR 682 QRKNBBNR 683 QRKNBNRB 684 QBRKNNBR 685 QRKBNNBR 686 QRKNNBBR 687 QRKNNRBB 688 BBRQKNNR 689 BRQBKNNR
690 BRQKNBNR 691 BRQKNNRB 692 RBBQKNNR 693 RQBBKNNR 694 RQBKNBNR 695 RQBKNNRB 696 RBQKBNNR 697 RQKBBNNR 698 RQKNBBNR 699 RQKNBNRB
700 RBQKNNBR 701 RQKBNNBR 702 RQKNNBBR 703 RQKNNRBB 704 BBRKQNNR 705 BRKBQNNR 706 BRKQNBNR 707 BRKQNNRB 708 RBBKQNNR 709 RKBBQNNR
710 RKBQNBNR 711 RKBQNNRB 712 RBKQBNNR 713 RKQBBNNR 714 RKQNBBNR 715 RKQNBNRB 716 RBKQNNBR 717 RKQBNNBR 718 RKQNNBBR 719 RKQNNRBB
720 BBRKNQNR 721 BRKBNQNR 722 BRKNQBNR 723 BRKNQNRB 724 RBBKNQNR 725 RKBBNQNR 726 RKBNQBNR 727 RKBNQNRB 728 RBKNBQNR 729 RKNBBQNR
730 RKNQBBNR 731 RKNQBNRB 732 RBKNQNBR 733 RKNBQNBR 734 RKNQNBBR 735 RKNQNRBB 736 BBRKNNQR 737 BRKBNNQR 738 BRKNNBQR 739 BRKNNQRB
740 RBBKNNQR 741 RKBBNNQR 742 RKBNNBQR 743 RKBNNQRB 744 RBKNBNQR 745 RKNBBNQR 746 RKNNBBQR 747 RKNNBQRB 748 RBKNNQBR 749 RKNBNQBR
750 RKNNQBBR 751 RKNNQRBB 752 BBRKNNRQ 753 BRKBNNRQ 754 BRKNNBRQ 755 BRKNNRQB 756 RBBKNNRQ 757 RKBBNNRQ 758 RKBNNBRQ 759 RKBNNRQB
760 RBKNBNRQ 761 RKNBBNRQ 762 RKNNBBRQ 763 RKNNBRQB 764 RBKNNRBQ 765 RKNBNRBQ 766 RKNNRBBQ 767 RKNNRQBB 768 BBQRKNRN 769 BQRBKNRN
770 BQRKNBRN 771 BQRKNRNB 772 QBBRKNRN 773 QRBBKNRN 774 QRBKNBRN 775 QRBKNRNB 776 QBRKBNRN 777 QRKBBNRN 778 QRKNBBRN 779 QRKNBRNB
780 QBRKNRBN 781 QRKBNRBN 782 QRKNRBBN 783 QRKNRNBB 784 BBRQKNRN 785 BRQBKNRN 786 BRQKNBRN 787 BRQKNRNB 788 RBBQKNRN 789 RQBBKNRN
790 RQBKNBRN 791 RQBKNRNB 792 RBQKBNRN 793 RQKBBNRN 794 RQKNBBRN 795 RQKNBRNB 796 RBQKNRBN 797 RQKBNRBN 798 RQKNRBBN 799 RQKNRNBB
800 BBRKQNRN 801 BRKBQNRN 802 BRKQNBRN 803 BRKQNRNB 804 RBBKQNRN 805 RKBBQNRN 806 RKBQNBRN 807 RKBQNRNB 808 RBKQBNRN 809 RKQBBNRN
810 RKQNBBRN 811 RKQNBRNB 812 RBKQNRBN 813 RKQBNRBN 814 RKQNRBBN 815 RKQNRNBB 816 BBRKNQRN 817 BRKBNQRN 818 BRKNQBRN 819 BRKNQRNB
820 RBBKNQRN 821 RKBBNQRN 822 RKBNQBRN 823 RKBNQRNB 824 RBKNBQRN 825 RKNBBQRN 826 RKNQBBRN 827 RKNQBRNB 828 RBKNQRBN 829 RKNBQRBN
830 RKNQRBBN 831 RKNQRNBB 832 BBRKNRQN 833 BRKBNRQN 834 BRKNRBQN 835 BRKNRQNB 836 RBBKNRQN 837 RKBBNRQN 838 RKBNRBQN 839 RKBNRQNB
840 RBKNBRQN 841 RKNBBRQN 842 RKNRBBQN 843 RKNRBQNB 844 RBKNRQBN 845 RKNBRQBN 846 RKNRQBBN 847 RKNRQNBB 848 BBRKNRNQ 849 BRKBNRNQ
850 BRKNRBNQ 851 BRKNRNQB 852 RBBKNRNQ 853 RKBBNRNQ 854 RKBNRBNQ 855 RKBNRNQB 856 RBKNBRNQ 857 RKNBBRNQ 858 RKNRBBNQ 859 RKNRBNQB
860 RBKNRNBQ 861 RKNBRNBQ 862 RKNRNBBQ 863 RKNRNQBB 864 BBQRKRNN 865 BQRBKRNN 866 BQRKRBNN 867 BQRKRNNB 868 QBBRKRNN 869 QRBBKRNN
870 QRBKRBNN 871 QRBKRNNB 872 QBRKBRNN 873 QRKBBRNN 874 QRKRBBNN 875 QRKRBNNB 876 QBRKRNBN 877 QRKBRNBN 878 QRKRNBBN 879 QRKRNNBB
880 BBRQKRNN 881 BRQBKRNN 882 BRQKRBNN 883 BRQKRNNB 884 RBBQKRNN 885 RQBBKRNN 886 RQBKRBNN 887 RQBKRNNB 888 RBQKBRNN 889 RQKBBRNN
890 RQKRBBNN 891 RQKRBNNB 892 RBQKRNBN 893 RQKBRNBN 894 RQKRNBBN 895 RQKRNNBB 896 BBRKQRNN 897 BRKBQRNN 898 BRKQRBNN 899 BRKQRNNB
900 RBBKQRNN 901 RKBBQRNN 902 RKBQRBNN 903 RKBQRNNB 904 RBKQBRNN 905 RKQBBRNN 906 RKQRBBNN 907 RKQRBNNB 908 RBKQRNBN 909 RKQBRNBN
910 RKQRNBBN 911 RKQRNNBB 912 BBRKRQNN 913 BRKBRQNN 914 BRKRQBNN 915 BRKRQNNB 916 RBBKRQNN 917 RKBBRQNN 918 RKBRQBNN 919 RKBRQNNB
920 RBKRBQNN 921 RKRBBQNN 922 RKRQBBNN 923 RKRQBNNB 924 RBKRQNBN 925 RKRBQNBN 926 RKRQNBBN 927 RKRQNNBB 928 BBRKRNQN 929 BRKBRNQN
930 BRKRNBQN 931 BRKRNQNB 932 RBBKRNQN 933 RKBBRNQN 934 RKBRNBQN 935 RKBRNQNB 936 RBKRBNQN 937 RKRBBNQN 938 RKRNBBQN 939 RKRNBQNB
940 RBKRNQBN 941 RKRBNQBN 942 RKRNQBBN 943 RKRNQNBB 944 BBRKRNNQ 945 BRKBRNNQ 946 BRKRNBNQ 947 BRKRNNQB 948 RBBKRNNQ 949 RKBBRNNQ
950 RKBRNBNQ 951 RKBRNNQB 952 RBKRBNNQ 953 RKRBBNNQ 954 RKRNBBNQ 955 RKRNBNQB 956 RBKRNNBQ 957 RKRBNNBQ 958 RKRNNBBQ 959 RKRNNQBB


Valid arrangements are such that the two B's cannot both be on odd or even positions and the K must be somewhere between the two R's.

As a test of your program or function you may get the checksum 38292381401040 from summing all (960+N) * SP(N) where N B R Q K is transliterated into 1 2 3 4 5 accordingly to get a decimal number from all N's 0-959. The start and end of this summation looks like:

( 960 + 0 ) * 22411353 +
( 960 + 1 ) * 24121353 +
( 960 + 2 ) * 24113253 +
.
.
.
( 960 + 958 ) * 35311224 +
( 960 + 959 ) * 35311422 = 38292381401040


This is Code Golf, shortest code wins.

• Worth to mention that the bishops must be placed on different-colored squares. Commented Feb 17 at 2:19
• @DannyuNDos – This info is not needed for the methods at the wikipedia link, but other method may exists so I've added it now. Also the K must be between the two R's. Commented Feb 17 at 10:50
• I was hoping that a bruteforce method like def fisher(n): return [p for p in distinct_permutations('BBQNNRKR') if is_subseq('RKR', p) and sum_of_indices('B',p) % 2 == 1][n] would work (ie list all permutations, and filter out those that don't have RKR and those that have bishops on same colour). I do get 960 positions, but apparently the order of permutations is not right.
– Stef
Commented Feb 17 at 11:02

# JavaScript (ES6), 117 bytes

This is based on the direct derivation method described on Wikipedia.

f=(n,i=Q=R=N=-1)=>i<7?"RKRNQB"[i++^n%4*2&&i^n/2&6?n/16%6^++Q?~-(j=n/96)%3+1+j%9/7^N++&&~-j*3/8^N?++R:3:4:5]+f(n,i):""


Try it online!

Or verify all results, using a cleaner implementation.

### Knight positions

Given $$\j=\lfloor n/96\rfloor \in[0\dots9]\$$, the 0-indexed position of the first knight is:

$$[0,0,0,0,1,1,1,2,2,3][j]$$

which can be obtained with:

~-j * 3 / 8 | 0


The 0-indexed position of the second knight is:

$$[1,2,3,4,2,3,4,3,4,4][j]$$

which can be obtained with:

~-j % 3 + 2 + j % 9 / 7 | 0


# C (gcc), 127 bytes

f(n,i,j,Q,R,N){for(i=Q=N=-1,R=75;i<7;)putchar(i++^n%4*2&&i^n/2&6?n/16%6^++Q?(j=n/96-1)%3+1+j%8/6^N++&&j*3/8^N?R^=25:78:81:66);}


Try it online!

# Charcoal, 8076 74 bytes

Ｎθ≔ＫＤ⁸→ηＦ²«§≔η⁻⊕⊗θιB≧÷⁴θ»§≔η§⌕ＡηωθQＦ⪪”)“∧⊟bＢ%⁰”χ§≔η§⌕ＡηωＩ§ι÷θ⁶NＦRKR§≔η⌕ηωι


Try it online! Link is to verbose version of code. Explanation:

Ｎθ


Input the position number.

≔ＫＤ⁸→η


Get a reference to 8 cells of the canvas. (Charcoal allows you to modify the canvas by writing to elements of this list, thus implicitly printing the result.)

Ｆ²«§≔η⁻⊕⊗θιB≧÷⁴θ»


Place the bishops. This also divides the input by 16.

§≔η§⌕ＡηωθQ


Place the queen.

Ｆ⪪”...”χ§≔η§⌕ＡηωＩ§ι÷θ⁶N


Place the knights by looking up their positions in a compressed string, as that was sadly golfier than computing the position directly. (Note that the second half of the look-up table has to take into account that the first knight has already been placed, so there are only four empty cells remaining.)

ＦRKR§≔η⌕ηωι


Place the remaining pieces.

# APL+WIN, 146 bytes.

Prompts for layout number. Uses compressed versions of the bishops' and knights' tables.

p←~i←(8⍴2)⊤+⎕av⍳'?è{~⍨ÏÛ|+⊤≤÷+⍉○∪'[16|n←0]⋄p[(i/⍳8)[6|n←⌊n÷16]]←2⋄p[((5⍴2)⊤¯32+⎕av⍳'8421,*)&%#'[⌊n÷6])/(p=0)/⍳8]←3⋄p[((p=0)/⍳8)[0 2]]←4⋄'KBQNR'[p]


Unfortunately Dyalog Classic's ⎕av does not match that of my APL so no TIO available. Test cases:

n=0 BBQNNRKR, n=518 RNBQKBNR, n=959 RKRNNQBB


# Funge-98, 182 bytes

"RBUS"4(&:4%2*1+'B\9p4/:4%2*'B\9p4/:6%'Qa13C1g::7/'Na13C$:7%'Na13C00'Ra13C01'Ra13C00'Ka13C>::8-6j5+1,g9_@ '>1p"HTRF"4($ffp>3k0p>:9g' -3j7+1_O00g-9j7p00+1g00_'Q\9p$6/ffg1)1R  Try it online! Uses the direct derivation method from Wikipedia. Contains non-printable characters, so here is a hex dump: 00000000: 2252 4255 5322 3428 263a 3425 322a 312b "RBUS"4(&:4%2*1+ 00000010: 2742 5c39 7034 2f3a 3425 322a 2742 5c39 'B\9p4/:4%2*'B\9 00000020: 7034 2f3a 3625 2751 6131 3343 3167 3a3a p4/:6%'Qa13C1g:: 00000030: 372f 274e 6131 3343 243a 3725 274e 6131 7/'Na13C$:7%'Na1
00000040: 3343 3030 2752 6131 3343 3031 2752 6131  3C00'Ra13C01'Ra1
00000050: 3343 3030 274b 6131 3343 3e3a 3a38 2d36  3C00'Ka13C>::8-6
00000060: 6a35 2b31 2c67 395f 400a 070e 151c 0f16  j5+1,g9_@.......
00000070: 1d17 1e1f 273e 3170 2248 5452 4622 3428  ....'>1p"HTRF"4(
00000080: 2466 6670 3e33 6b30 703e 3a39 6727 202d  $ffp>3k0p>:9g' - 00000090: 336a 372b 315f 4f30 3067 2d39 6a37 7030 3j7+1_O00g-9j7p0 000000a0: 302b 3167 3030 5f27 515c 3970 2436 2f66 0+1g00_'Q\9p$6/f
000000b0: 6667 3129 3152                           fg1)1R


# Perl 5-Minteger -n, 144 152 bytes

@r[$_%4*2+1,$_/4%4*2]=(B,B);map{$q=$_;$_||=!$q--&&substr QNNRKR,$i++,1for@r[0..7]}$_/16%6,(($t=$_/96)>3)+($t>6)+($t>8),(0..3,1..3,2,3,3)[\$t],0,0,0;say@r


Try it online!

• Can't get it to work for 672-959. Throws "Modification of a read-only value attempted". Commented Mar 6 at 19:47
• @KjetilS Fixed that. It didn't like the constants in the loop list. Also fixed another bug with the bishop placement. Commented Mar 6 at 21:51