cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A378488 Table T(n,k) read by rows where in the n-th row the k-th column is the permutation rank of the k-th solution to the n-queens problem in a n X n board.

This page as a plain text file.
%I A378488 #6 Dec 12 2024 23:15:21
%S A378488 0,0,0,10,13,10,13,36,44,50,69,75,83,106,109,186,346,373,533,186,346,
%T A378488 373,533,980,1032,1090,1108,1188,1244,1399,1515,1519,1905,1956,2074,
%U A378488 2090,2197,2210,2390,2649,2829,2842,2949,2965,3083,3134,3520,3524,3640,3795,3851
%N A378488 Table T(n,k) read by rows where in the n-th row the k-th column is the permutation rank of the k-th solution to the n-queens problem in a n X n board.
%C A378488 The length of the n-th row is A000170(n) for n >= 4.
%H A378488 Wikipedia, <a href="https://en.wikipedia.org/wiki/Eight_queens_puzzle">Eight queens puzzle</a>
%F A378488 a(n) = 0 if no solution exists or n = 1.
%e A378488 Table T(n,k) reads as follows:
%e A378488  n / k
%e A378488 -------------------------------------------
%e A378488  1 | 0
%e A378488  2 | 0
%e A378488  3 | 0
%e A378488  4 | 10, 13
%e A378488  5 | 10, 13, 36, 44, 50, 69, 75, 83, 106, 109
%e A378488  6 | 186, 346, 373, 533
%e A378488 For a table of 4 by 4 one of the solutions for placing the 4 queens is [(0,1),(1,3),(2,0),(3,2)] and its compact representation is [1, 3, 0, 2],
%e A378488 this resulting representation is a permutation that can be ranked and its rank is 10.
%e A378488 T(1) = [0]
%e A378488   *-*
%e A378488   |Q| Permutation: [0], Rank: 0
%e A378488   *-*
%e A378488 T(2) = [0] because of no solution and n < 4.
%e A378488 T(4) = [10, 13]
%e A378488      0 1 2 3         0 1 2 3
%e A378488    +---------+     +---------+
%e A378488  0 | . Q . . |     | . . Q . |
%e A378488  1 | . . . Q |     | Q . . . |
%e A378488  2 | Q . . . |     | . . . Q |
%e A378488  3 | . . Q . |     | . Q . . |
%e A378488    +---------+     +---------+
%e A378488    Permutation:    Permutation:
%e A378488     [1, 3, 0, 2]    [2, 0, 3, 1]
%e A378488    Rank: 10        Rank: 13
%e A378488 T(6) = [186, 346, 373, 533]:
%e A378488      0 1 2 3 4 5          0 1 2 3 4 5          0 1 2 3 4 5          0 1 2 3 4 5
%e A378488    +-------------+      +-------------+      +-------------+      +-------------
%e A378488  0 | . Q . . . . |      | . . Q . . . |      | . . . Q . . |      | . . . . Q . |
%e A378488  1 | . . . Q . . |      | . . . . . Q |      | Q . . . . . |      | . . Q . . . |
%e A378488  2 | . . . . . Q |      | . Q . . . . |      | . . . . Q . |      | Q . . . . . |
%e A378488  3 | Q . . . . . |      | . . . . Q . |      | . Q . . . . |      | . . . . . Q |
%e A378488  4 | . . Q . . . |      | Q . . . . . |      | . . . . . Q |      | . . . Q . . |
%e A378488  5 | . . . . Q . |      | . . . Q . . |      | . . Q . . . |      | . Q . . . . |
%e A378488    +-------------+      +-------------+      +-------------+      +-------------+
%e A378488    Permutation:         Permutation:         Permutation:         Permutation:
%e A378488     [1, 3, 5, 0, 2, 4]   [2, 5, 1, 4, 0, 3]   [3, 0, 4, 1, 5, 2]   [4, 2, 0, 5, 3, 1]
%e A378488    Rank:186             Rank:346             Rank: 373            Rank: 533
%o A378488 (Python)
%o A378488 from sympy.combinatorics import Permutation
%o A378488 def queens(n, i = 0, cols=0, pos_diags=0, neg_diags=0, sol=None):
%o A378488     if sol is None: sol = []
%o A378488     if i == n: yield sol[:]
%o A378488     else:
%o A378488         neg_diag_mask_ = 1 << (i+n)
%o A378488         col_mask = 1
%o A378488         for j in range(n):
%o A378488             col_mask <<= 1
%o A378488             pos_diag_mask = col_mask << i
%o A378488             neg_diag_mask = neg_diag_mask_ >> (j+1)
%o A378488             if not (cols & col_mask or pos_diags & pos_diag_mask or neg_diags &
%o A378488 neg_diag_mask):
%o A378488                 sol.append(j)
%o A378488                 yield from queens(n, i + 1,
%o A378488                                   cols | col_mask,
%o A378488                                   pos_diags | pos_diag_mask,
%o A378488                                   neg_diags | neg_diag_mask,
%o A378488                                   sol)
%o A378488                 sol.pop()
%o A378488 row = lambda n: [Permutation(sol).rank() for sol in queens(n)]  if n >= 4 else [0]
%Y A378488 Cf. A000170.
%K A378488 nonn,tabf
%O A378488 1,4
%A A378488 _DarĂ­o Clavijo_, Nov 28 2024