;Ė{~b.hℕ₁≜∧.¬{ġh₃hᵐs₂ᶠ-ᵐ=}∧}ⁱ⁽↔
在线尝试!
万一重要:2字节的高尔夫运动是有可能的,这要归功于我在应对这一挑战后所要求的功能。
说明
我们以相反的顺序(例如)迭代生成序列作为列表,最后将其反向[2,2,1,1,2,1,1]
。
这里有两个嵌套谓词。让我们从内而外看它们。第一个ġh₃hᵐs₂ᶠ-ᵐ=
取一个候选子序列,a(n),a(n-1),...,a(0)
并确定是否a(n),a(n-k),a(n-2k)
是某一个的算术序列k
。
ġ Group the list into equal-length sublists (with the possible exception of
the last sublist, which might be shorter)
h₃ Get the first 3 sublists from that list
hᵐ and get the head of each of those 3 sublists
We now have a list containing a(n),a(n-k),a(n-2k) for some k
s₂ᶠ Find all 2-element sublists of that list: [a(n),a(n-k)] and [a(n-k),a(n-2k)]
-ᵐ Find the difference of each pair
= Assert that the two pairwise differences are equal
例如,输入为[1,2,1,1,2,1,1]
:
ġ has possible outputs of
[[1],[2],[1],[1],[2],[1],[1]]
[[1,2],[1,1],[2,1],[1]]
[[1,2,1],[1,2,1],[1]]
[[1,2,1,1],[2,1,1]]
[[1,2,1,1,2],[1,1]]
[[1,2,1,1,2,1],[1]]
[[1,2,1,1,2,1,1]]
h₃ has possible outputs of
[[1],[2],[1]]
[[1,2],[1,1],[2,1]]
[[1,2,1],[1,2,1],[1]]
hᵐ has possible outputs of
[1,2,1]
[1,1,2]
[1,1,1]
s₂ᶠ has possible outputs of
[[1,2],[2,1]]
[[1,1],[1,2]]
[[1,1],[1,1]]
-ᵐ has possible outputs of
[-1,1]
[0,-1]
[0,0]
= is satisfied by the last of these, so the predicate succeeds.
下一个谓词向外,~b.hℕ₁≜∧.¬{...}∧
输入一个子序列,a(n-1),a(n-2),...,a(0)
然后输出下一个更大的子序列a(n),a(n-1),a(n-2),...,a(0)
。
~b.hℕ₁≜∧.¬{...}∧
~b. The input is the result of beheading the output; i.e., the output is
the input with some value prepended
.h The head of the output
ℕ₁ is a natural number >= 1
≜ Force a choice as to which number (I'm not sure why this is necessary,
but the code doesn't work without it)
∧ Also,
. the output
¬{...} does not satisfy the nested predicate (see above)
I.e. there is no k such that a(n),a(n-k),a(n-2k) is an arithmetic sequence
∧ Break unification with the output
最后,主谓词;Ė{...}ⁱ⁽↔
采用输入数字并输出该序列的许多项。
;Ė{...}ⁱ⁽↔
; Pair the input number with
Ė the empty list
{...}ⁱ⁽ Using the first element of the pair as the iteration count and the second
element as the initial value, iterate the nested predicate (see above)
↔ Reverse, putting the sequence in the proper order