这个挑战的目标是产生一个n函数,它计算将n X 1网格划分为三角形的方法的数量,其中三角形的所有顶点都在网格点上。
例如,有14种方法来划分2x1网格,因此f(2) = 14通过以下分区进行划分

其中分区分别具有2、2、2、4和2个不同的方向。
这是密码-高尔夫,所以最短的代码就赢了。
发布于 2018-11-28 17:36:55
·LÉœÙεÅγo;P}O很慢是因为排列的内在。
· # Double the (implicit) input
L # Create a list in the range [1, doubled_input]
É # Check for each if they're odd (1 if truthy, 0 is falsey)
# We now have a list of n 0s and n 1s (n being the input)
œ # Get all permutations of that list
Ù # Only leave the unique permutations
ε } # Map each permutation to:
Åγ # Run-length encode the current value (short for `γ€g`)
o # Take 2 to the power for each
; # Halve each
P # Take the product of the mapped permutation
O # Sum all mapped values together (and output implicitly)发布于 2018-11-28 09:49:02
https://codegolf.stackexchange.com/questions/176646
复制相似问题