# 超立方体元素

19

### 测试用例

Input = 0
Output = [1]

Input = 1
Output = [1,2]

Input = 3
Output = [1,6,12,8]

Input = 10
Output = [1, 20, 180, 960, 3360, 8064, 13440, 15360, 11520, 5120, 1024]

Input = 12
Output = [1, 24, 264, 1760, 7920, 25344, 59136, 101376, 126720, 112640, 67584, 24576, 4096]

Answers:

11

# J，13个字节

[:p.2&^;\$&_.5

@alephalpha的PARI / GP答案启发。使用J.js在线尝试。

### 码

[:p.2&^;\$&_.5  Monadic verb. Argument: n

\$&_.5  Yield an array of n instances of -0.5.
2&^        Compute 2^n.
;       Link the results to the left and right.
This specifies a polynomial of n roots (all -0.5)
with leading term 2^n.
[:p.           Convert from roots to coefficients.

10

# MATL，8个字节

1i:"2:X+

### 怎么运行的

1        % Push 1.
i:      % Push [1 ... input].
"     % Begin for-each loop:
2:   %   Push [1 2].
X+ %   Take the convolution product of the bottom-most stack item and [1 2].

5

Luis Mendo

1

rayryeng-恢复莫妮卡

@rayryeng我们想念您:-)

8

## MATL，12字节

Q:q"H@^G@Xn*

### 说明

% implicit: input number "n"
Q:q      % generate array[0,1,...,n]
"        % for each element "m" from that array
H@^    % compute 2^m
G      % push n
@      % push m
Xn     % compute n choose m
*      % multiply
% implicit: close loop and display stack contents

8

# Mathematica，29个字节

CoefficientList[(1+2x)^#,x]&

> F := CoefficientList[(1+2x)^#,x]&`
> F[10]
{1,20,180,960,3360,8064,13440,15360,11520,5120,1024}

6

# APL，15 11字节

1,(2*⍳)×⍳!⊢

⍳!⊢  ⍝ Get n choose m for each m from 1 to n
×     ⍝ Multiply elementwise by
(2*⍳)      ⍝ 2^m for m from 1 to n
1,           ⍝ Tack 1 onto the front to cover the m=0 case

5

# 果冻，8个字节

0rð2*×c@

0r            Helper link. Input is n, inclusive range from 0 to n. Call the result r.
ð           Start a new, dyadic link. Input is r, n.
2*         Vectorized 2 to the power of r
×c@      Vectorized multiply by n nCr r. @ switches argument order.

4

## TI-BASIC，10个字节

3^Ansbinompdf(Ans,2/3

PhiNotPi '02

4

## 果酱（17 14字节）

ri_3@#_2+@#\b`

ri     e# Read an integer n from stdin
_3@#   e# Push 3^n to the stack
_2+    e# Duplicate and add 2, giving a base-3^n representation of x+2
@#     e# Raise to the power of n
\b`    e# Convert into a vector of base-3^n digits and format for output

1a{0X\$2f*+.+}ri*`

1a{0X\$+_]:.+}ri*`

2,rim*{1b_0a*2@#+}%z1fb`

2,rim*1fb_0af*2@f#.+z1fb`

3

## ES6，71个字节

n=>[...Array(n+1)].fill(n).map(b=(n,i)=>!i?1:i>n?0:b(--n,i-1)*2+b(n,i))

3

# Pyth，10个 9字节

.<L.cQdhQ

L映射保存一个字节：.<L.cQdhQ
isaacg '16

2

# 05AB1E，9个字节

WƒNoZNc*,

W          # Push input and store in Z
ƒ         # For N in range(0, input + 1)
No       # Compute 2**N
ZNc    # Compute Z nCr N
*   # Multiply
,  # Pop and print

2

# 朱莉娅，31个字节

n->[2^m*binomial(n,m)for m=0:n]

1

# Ruby，修订版B 57字节

->n{a=[1]+[0]*n
(n*n).downto(n){|i|a[1+j=i%n]+=2*a[j]}
a}

# Ruby，修订版A 61字节

->n{a=[1]+[0]*n
n.times{|i|i.downto(0){|j|a[j+1]+=2*a[j]}}
a}

1个面变为立方体并生成1对面（上方1个，下方1个）

4条边成为面并生成4对边（上方4条，下方4条）

4个顶点变为边并生成4对顶点（上方4个，下方4个）

f=->n{a=[1]+[0]*n                  #make an array with the inital point and space for other dimensions
n.times{|i|                      #iteratively expand dimension by dimension
i.downto(0){|j|a[j+1]+=2*a[j]} #iterating downwards (to avoid interferences) add the 2 new elements generated by each existing element.
}
a}                                 #return the array

p f[gets.to_i]
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.