# 生成Skolem序列

10

## Skolem序列

``````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
``````

``````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)
``````

## 目的

``````0, 1, 0, 0, 6, 10, 0, 0, 504, 2656, 0, 0, 455936, 3040560, 0, 0, 1400156768
``````

## 规则和计分

PhiNotPi

2

1

2

1
@boothby，您只是称呼Knuth是个傻瓜吗？

8

### GolfScript，48个 46个字符

``````:b,1,{)2\?){{.2\$&!{.2\$|@@}*.+.4b?<}do;;}+%}@/,
``````

``````1: 000011        000110 001100 011000 110000
2: 010111 101011 101110        011101 110101 111010
``````

``````:b           # save the input into variable b for later use
,            # make the list 0..b-1 (the outer loop)
1,           # puts the list [0] on top of the stack - initially the only possible
# combination
{)           # {...}@/ does the outer loop counting from i=1 to b
2\?)       # computes the smalles possible bit mask m=2^i+1 with two bits set
# and distance of those equal to i (i.e. i=1: 11, i=2: 101, ...)
{          # the next loop starts with this bitmask (prepended to code via
# concatination {...}+
# the loop itself iterates the top of the stack, i.e. at this point
# the result array
# stack here contains item of result array (e.g. 00000011)
{        # the inner-most loop tries all masks with the current item in the result set
.2\$&!  # do item and result set share not single bit? then - {...}*
{
.2\$| # then generate the new entry by or-ing those two
@@   # push it down on the stack (i.e. put working items to top)
}*
.+     # shift the bit mask left by one
.4b?<  # if still in the range loop further
}do;;    # removes the remainders of the loop (i.e. item processed and mask)
}+%        # stack now contains the new result array
}@/
,            # length of result array, i.e. the number of Skolem sequences
``````

6

### J表达式，47个字符

`````` +/*/"1((=&{:+.2-#@])#;.2)\"1~.(i.!+:y)A.,~>:i.y
``````

``````    y=:5
+/*/"1((=&{:+.2-#@])#;.2)\"1~.(i.!+:y)A.,~>:i.y
10
``````

`y=:5`在我的机器上花费大约30秒。

• `~.(i.!+:y)A.,~>:i.y`生成的每个排列`1 2 .. y 1 2 .. y`并删除重复的条目
• `((=&{:+.2-#@])#;.2)\"1` 计算：
• `(...)\"1` 每行的每个前缀：
• `#;.2` 在最后一个元素的每次出现之前对元素进行计数
• `#@]` 计算计数数（即最后一个元素的出现数）
• `=&{:` 确定计数列表和原始列表的“最后一个元素”的“相等”。
• `+.`是逻辑或。`=&{:+.2-#@]`读取为“ [计数列表和原始列表]的最后一个元素相等，或者[计数列表]中只有一个元素而不是两个”。
• `*/"1` 在条件表的行上相乘（逻辑与），确定哪些排列是Skolem序列。
• `+/` 将一和零相加。

6

## GolfScript（46个字符）

``````:&1,\,{0,2@)?)2&*{2\${1\$^}%@+\2*}*;+}/{4&?(=},,
``````

### 速度

``````~:&1,\,{0,\).2\?)2&*@-{.{[\].~^.@~+<{;}*}+3\$%@+\2*}*;\;}/{4&?(=},,
``````

John Dvorak 2013年

5

### GolfScript，49个字符

``````~:/..+?:d(,{d+/base(;:w;/,{.w?)w>1\$?=},,/=},,/1=+
``````

@boothby这是第一次直接尝试。我们经常不得不考虑决策速度与大小的关系-代码高尔夫球的大小就是大小。这就是为什么我还添加了快速版本的原因-该版本原本要长得多，但现在更短。

0

## 贤者，70

``````sum(1for i in DLXCPP([(i-1,j,i+j)for i in[1..n]for j in[n..3*n-i-1]]))
``````

``````11001
10100
01001
00011
00010
``````

``````10100
01001
00010
``````

``````  a   |  b
001000|001001000000 # S[b] = S[b+a+1] = a
``````

2013年

@Ray如果我计算`len(list(...))`n = 16，我的计算机就会死掉。并且它会完全杀死运行时。

2013年