首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将网格划分为三角形

将网格划分为三角形
EN

Code Golf用户
提问于 2018-11-27 21:10:02
回答 3查看 1.8K关注 0票数 20

目标

这个挑战的目标是产生一个n函数,它计算将n X 1网格划分为三角形的方法的数量,其中三角形的所有顶点都在网格点上。

示例

例如,有14种方法来划分2x1网格,因此f(2) = 14通过以下分区进行划分

其中分区分别具有2、2、2、4和2个不同的方向。

评分

这是密码-高尔夫,所以最短的代码就赢了。

EN

回答 3

Code Golf用户

回答已采纳

发布于 2018-11-28 17:36:55

05AB1E,13 字节数

代码语言:javascript
复制
·LÉœÙεÅγo;P}O

@Bubbler果冻回答港。

很慢是因为排列的内在。

在网上试试验证前四个输入.

解释:

代码语言:javascript
复制
·                # 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)
票数 2
EN

Code Golf用户

发布于 2018-11-28 09:49:02

帕里/GP,43字节

根据OEIS,该序列的生成函数是

\frac{1}{2}\left(\sqrt{\frac{1-x}{1-9x}}+1\right)
代码语言:javascript
复制
n->Vec(sqrt((1-x)/(1-9*x)+O(x^n++))+1)[n]/2

在网上试试!

票数 2
EN

Code Golf用户

发布于 2018-11-27 23:11:07

Python 3,51字节

代码语言:javascript
复制
lambda n:-~n*(n<2)or(10-6/n)*f(n-1)-(9-18/n)*f(n-2)

在网上试试!

完美港的答案

票数 1
EN
页面原文内容由Code Golf提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://codegolf.stackexchange.com/questions/176646

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档