4Å1λ£₁λ¨Â¦¦s¦¦*O+
不小于现有的05AB1E答案,但是我想尝试新的05AB1E版本的递归功能作为自己的练习。也许可以打几个字节。编辑:确实可以,请参见下面@Grimy的05AB1E答案的递归版本,它是13 个字节。
ñ
ñ£
è
£
说明:
a (n )= a (n − 1 )+ ∑n − 1k = 2(一(ķ )⋅ 一个(ñ - 1 - ķ ))
a (0 )= a (1 )= a (2 )= a (3 )= 1
λ # Create a recursive environment,
£ # to output the first (implicit) input amount of results after we're done
4Å1 # Start this recursive list with [1,1,1,1], thus a(0)=a(1)=a(2)=a(3)=1
# Within the recursive environment, do the following:
λ # Push the list of values in the range [a(0),a(n)]
¨ # Remove the last one to make the range [a(0),a(n-1)]
 # Bifurcate this list (short for Duplicate & Reverse copy)
¦¦ # Remove the first two items of the reversed list,
# so we'll have a list with the values in the range [a(n-3),a(0)]
s # Swap to get the [a(0),a(n-1)] list again
¦¦ # Remove the first two items of this list as well,
# so we'll have a list with the values in the range [a(2),a(n-1)]
* # Multiply the values at the same indices in both lists,
# so we'll have a list with the values [a(n-3)*a(2),...,a(0)*a(n-1)]
O # Take the sum of this list
₁ + # And add it to the a(n-1)'th value
# (afterwards the resulting list is output implicitly)
@Grimy的 13 字节版本(如果您还没有,请确保对他的回答进行投票!):
1λ£λ1šÂ¨¨¨øPO
ñ
可以再次更改为基于0的索引或无限列表:
1λèλ1šÂ¨¨¨øPO
λλ1šÂ¨¨¨øPO
a (0 )= 1
说明:
a (n )= ∑n − 1k = 2(一(ķ )⋅ 一个(ñ - 2 - ķ ))
a (− 1 )= a (0 )= a (1 )= a (2 )= 1
λ # Create a recursive environment,
£ # to output the first (implicit) input amount of results after we're done
1 # Start this recursive list with 1, thus a(0)=1
# Within the recursive environment, do the following:
λ # Push the list of values in the range [a(0),a(n)]
1š # Prepend 1 in front of this list
 # Bifurcate the list (short for Duplicate & Reverse copy)
¨¨¨ # Remove (up to) the last three value in this reversed list
ø # Create pairs with the list we bifurcated earlier
# (which will automatically remove any trailing items of the longer list)
P # Get the product of each pair (which will result in 1 for an empty list)
O # And sum the entire list
# (afterwards the resulting list is output implicitly)
a(n-1-k)
为a(n-k)
,对吗?