CJam,48 46字节
li(_S*"/\\":T+\{_N@S+TW%/S2**" /"/"\ "f/:+T*}*
基于问题1和2的简单递归方法。
在线尝试。
怎么运行的
li( " L := int(input()) - 1 ";
_S* " A := L * ' ' ";
"/\\":T+ " A += (T := '/\') ";
\{ " do L times: ";
_N " push A, '\n' ";
@S+ " A += ' ' ";
TW%/ " B := A.split(reverse(T)) ";
S2** " A := ' '.join(B) ";
" /"/ " B := A.split(' /') ";
"\ "f/ " C := { X.split('\ ') : X ∊ B } ";
:+T* " A := T.join(sum(C, [])) ";
}* " ";
CJam,51个字节
li__2mL,1a\{2_@##)1$f*+}/<f{2b_" /\\"2/f=@@,-S*\N}
我更喜欢这种方法,但是它不能与递归方法竞争。即使消除了2mL
(这至少导致O(2 n)执行时间),我仍然有48个字节...
这种方法将/\
s 编码为1,并将它们之间的双倍空格编码为0。考虑到结果数组的二进制数,我们看到第n行的配置对应于大于1 的第n个整数,该整数可以表示为不同费马数的乘积(形式为2 2 k +1的整数)。
怎么运行的
li__2mL,1a " push L := int(input()), L, R := range(log(L)/log(2)), A := [1] ";
\{2_@##)1$f*+}/ " for I in R: A += { a × 2**(2**I) : a ∊ A } ";
< " A := A[:L] ";
f{ " for I in R: push L, I ";
2b_" /\\"2/ " push (B := base(I, 2)), B, S := [ ' ' '/\' ] ";
f= " for J in I: J := S[J] ";
@@,-S*\N " push (L - len(B)) * ' ', J, '\n' ";
} " ";