Skolem sequences
A Skolem sequence is a sequence of 2n
numbers where every number i
between 1
and n
occurs exactly twice, and the distance between the two occurrences of i
is exactly i
steps.
Here are some examples of Skolem sequences:
1 1
1 1 4 2 3 2 4 3
16 13 15 12 14 4 7 3 11 4 3 9 10 7 13 12 16 15 14 11 9 8 10 2 6 2 5 1 1 8 6 5
The following sequences are not Skolem sequences:
1 2 1 2 (The distance between the 1's is 2, not 1)
3 1 1 3 (The number 2 is missing)
1 1 2 1 1 2 (There are four 1's)
Objective
Write a program, function, or expression to count the number of all Skolem sequences of a given length.
More explicitly, your input is an integer n
, and your output is the number of Skolem sequences of length 2n
.
This sequence has an OEIS entry.
For n = 0
, you may return either 0
or 1
.
The first few values, starting from 0
, are
0, 1, 0, 0, 6, 10, 0, 0, 504, 2656, 0, 0, 455936, 3040560, 0, 0, 1400156768
Rules and scoring
This is code golf. Output format is lax within reason.
0, 1, 0, 0, 6...
in your question? Is that the code snippet, if so what language is that? \$\endgroup\$0
? If you're going to admit0
as a valid input then the output should be1
. \$\endgroup\$