# 矩形假分形

13

### 样本输入和输出

``````10

ABDDFFFFHHHHHHHHJJJJJJJJJJJJJJJJ
CCDDFFFFHHHHHHHHJJJJJJJJJJJJJJJJ
EEEEFFFFHHHHHHHHJJJJJJJJJJJJJJJJ
EEEEFFFFHHHHHHHHJJJJJJJJJJJJJJJJ
GGGGGGGGHHHHHHHHJJJJJJJJJJJJJJJJ
GGGGGGGGHHHHHHHHJJJJJJJJJJJJJJJJ
GGGGGGGGHHHHHHHHJJJJJJJJJJJJJJJJ
GGGGGGGGHHHHHHHHJJJJJJJJJJJJJJJJ
IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJ
IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJ
IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJ
IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJ
IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJ
IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJ
IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJ
IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJ
``````

### 选择标准

marinus 2014年

2
@marinus 4的幂有什么特别之处？也许您误解了这个例子？

@KendallFrey，不，仅需要n个唯一的可打印字符。
Hand-E-Food

mniip

10

# APL，25个字符/字节*

``````{⍉⍣⍵⊃{a,⍺⍴⍨⍴a←⍉⍪⍵}/⌽⍵↑⎕A}
``````

``````{                   ⍵↑⎕A}   ⍝ take the first ⍵ letters
⊃{           }/⌽        ⍝ fold over them, using the first one as initial accum. value
a←⍉⍪⍵           ⍝    ensure the accum. is a table, transpose it and call it 'a'
⍺⍴⍨⍴                ⍝    make a table as large as 'a' filled with the next letter
a,                    ⍝    append it to the right of 'a' and loop as new accumulator
⍉⍣⍵                        ⍝ transpose the result as many times as the original ⍵ number
``````

``````      {⍉⍣⍵⊃{a,⍺⍴⍨⍴a←⍉⍪⍵}/⌽⍵↑⎕A}¨⍳8
A AB  AB  ABDD  ABDD  ABDDFFFF  ABDDFFFF  ABDDFFFFHHHHHHHH
CC  CCDD  CCDD  CCDDFFFF  CCDDFFFF  CCDDFFFFHHHHHHHH
EEEE  EEEEFFFF  EEEEFFFF  EEEEFFFFHHHHHHHH
EEEE  EEEEFFFF  EEEEFFFF  EEEEFFFFHHHHHHHH
GGGGGGGG  GGGGGGGGHHHHHHHH
GGGGGGGG  GGGGGGGGHHHHHHHH
GGGGGGGG  GGGGGGGGHHHHHHHH
GGGGGGGG  GGGGGGGGHHHHHHHH
``````

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
*：APL可以在它自己的（传统）被写入的单字节字符集即APL符号映射到上部128个字节值。因此，出于计分的目的，仅使用ASCII字符和APL符号的N个字符的程序可以认为是N个字节长。

9

### GolfScript，30个字符

``````~(,[0`]{{[49+]1\$,*+}+%zip}@/n*
``````

``````> 7
01335555
22335555
44445555
44445555
66666666
66666666
66666666
66666666
``````

Timwi 2014年

@Timwi我刚刚测试了它，它对我有用。输出已转置，但未在问题中指定方向。
2014年

Timwi 2014年

@Howard Hm，这就是我的理解“并且以前的区域保持不变”。他说前两个字符可能在任何角落，但他没有说方向可能会改变。

7

## Python 2.7-85 103

``````s=[]
for i in range(input()):x=1<<i/2;s=zip(*s+[chr(65+i)*x]*x)
for i in s:print''.join(i)
``````

``````>>> 1<<(2*3)
64
>>> 1<<2*3
64
>>> 2**2*3
12
>>> 2**(2*3)
64
``````

``````10
01335555777777779999999999999999
22335555777777779999999999999999
44445555777777779999999999999999
44445555777777779999999999999999
66666666777777779999999999999999
66666666777777779999999999999999
66666666777777779999999999999999
66666666777777779999999999999999
88888888888888889999999999999999
88888888888888889999999999999999
88888888888888889999999999999999
88888888888888889999999999999999
88888888888888889999999999999999
88888888888888889999999999999999
88888888888888889999999999999999
88888888888888889999999999999999
``````

1

5

## Ruby，88岁

``````s=[?A]
66.upto(64+gets.to_i){|i|x=i.chr*y=s.size;i%2<1?s.map!{|r|r+x}:s+=[x*2]*y}
puts s
``````

N = 8的示例用法：

``````echo 8 | rectangular-pseudo-fractal.rb
``````

``````ABDDFFFFHHHHHHHH
CCDDFFFFHHHHHHHH
EEEEFFFFHHHHHHHH
EEEEFFFFHHHHHHHH
GGGGGGGGHHHHHHHH
GGGGGGGGHHHHHHHH
GGGGGGGGHHHHHHHH
GGGGGGGGHHHHHHHH
``````

N = 10

``````echo 10 | rectangular-pseudo-fractal.rb
``````

``````ABDDFFFFHHHHHHHHJJJJJJJJJJJJJJJJ
CCDDFFFFHHHHHHHHJJJJJJJJJJJJJJJJ
EEEEFFFFHHHHHHHHJJJJJJJJJJJJJJJJ
EEEEFFFFHHHHHHHHJJJJJJJJJJJJJJJJ
GGGGGGGGHHHHHHHHJJJJJJJJJJJJJJJJ
GGGGGGGGHHHHHHHHJJJJJJJJJJJJJJJJ
GGGGGGGGHHHHHHHHJJJJJJJJJJJJJJJJ
GGGGGGGGHHHHHHHHJJJJJJJJJJJJJJJJ
IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJ
IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJ
IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJ
IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJ
IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJ
IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJ
IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJ
IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJ
``````

@LegoStormtroopr添加了一些示例，但是与问题的格式完全相同。
Paul Prestidge 2014年

4

J，57 43

``````(,`,.@.(=/@\$@[)\$\${&a.@(66+2&^.@#@,)^:)1\$'A'
``````

``````5 (,`,.@.(=/@\$@[)\$\${&a.@(66+2&^.@#@,)^:)1\$'A'
ABDDFFFF
CCDDFFFF
EEEEFFFF
EEEEFFFF

7 (,`,.@.(=/@\$@[)\$\${&a.@(66+2&^.@#@,)^:)1\$'A'
ABDDFFFFHHHHHHHH
CCDDFFFFHHHHHHHH
EEEEFFFFHHHHHHHH
EEEEFFFFHHHHHHHH
GGGGGGGGHHHHHHHH
GGGGGGGGHHHHHHHH
GGGGGGGGHHHHHHHH
GGGGGGGGHHHHHHHH
``````

C和D都水平延伸。它们应水平和垂直交替。
Hand-E-Food

@ Hand-E-Food你是对的。感谢您指出了这一点。我已经固定了代码（并发布了）。
barbermot 2014年

4

MATLAB，86个字符

``````function M=f(n)
M='';
if n
M=cat(mod(n,2)+1,f(n-1),64+n*ones(2.^fix(n/2-[.5,1])));
end
``````

``````>> disp(f(7))
ACEEGGGG
BCEEGGGG
DDEEGGGG
DDEEGGGG
FFFFGGGG
FFFFGGGG
FFFFGGGG
FFFFGGGG
``````

@flawr：哦！明显！
knedlsepp 2015年

flawr

@flawr：在我看来我很浪费。;-)
knedlsepp 2015年

3

# q [73个字符]

``````{"c"\$64+{n:x 0;m:x 1;if[2>n;m:(),m];(o;\$[n-2*n div 2;,';,][m;(#m;#m 0)#o:n+1])}/[x-1;(1;1)]1}
``````

### 例

``````10
"ABDDFFFFHHHHHHHHJJJJJJJJJJJJJJJJ"
"CCDDFFFFHHHHHHHHJJJJJJJJJJJJJJJJ"
"EEEEFFFFHHHHHHHHJJJJJJJJJJJJJJJJ"
"EEEEFFFFHHHHHHHHJJJJJJJJJJJJJJJJ"
"GGGGGGGGHHHHHHHHJJJJJJJJJJJJJJJJ"
"GGGGGGGGHHHHHHHHJJJJJJJJJJJJJJJJ"
"GGGGGGGGHHHHHHHHJJJJJJJJJJJJJJJJ"
"GGGGGGGGHHHHHHHHJJJJJJJJJJJJJJJJ"
"IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJ"
"IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJ"
"IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJ"
"IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJ"
"IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJ"
"IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJ"
"IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJ"
"IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJ"

3
"AB"
"CC"

6
"ABDDFFFF"
"CCDDFFFF"
"EEEEFFFF"
"EEEEFFFF"
``````

3

# 滑行，59个字符

``````❶塊갠分감⓶左貶終辦감標가⓺貶⓹開上❶❶貶雙是不⒉갠乘⒉終가①上뀀❷②갠分小是增終❸⓷另要감右⓶갠加⓶終丟字⓶終丟겠終
``````

（如果我有以2为底的对数的说明，那么该程序可能会短很多，但我没有，所以我通过循环手动进行。）

## 带注释的代码

`n` 是输入。

``````❶ | n n

f = i => (1 << (i/2)) - 1;

w = f(n);

d = 1;
감 | n w f d

s = "";

for (y in [0..f(n-1)])
가⓺貶⓹開上 | w d M [s] y

if ((y & (y-1)) == 0) d *= 2;
❶❶貶雙是不⒉갠乘⒉終 | w d M [s] y

for (x in [0..w])
가①上 | w d M [s] y x

c = 64; // '@'
뀀 | w d M [s] y x c

if (x < d/2) c++;
❷②갠分小是增終 | w d M [s] y x c

a = x | y;
❸⓷另 | w d M [s] y c a

while (a > 0) { a >>= 1; c += 2; }
要감右⓶갠加⓶終丟 | w d M [s] y c

s += (char) c;
字⓶ | w d M [s] y
終丟 | w d M [s]

s += "\n"
겠 | w d M [s]

``````

## 输出量

``````ABDDFFFF
CCDDFFFF
EEEEFFFF
EEEEFFFF
``````

``````!"\$\$&&&&
##\$\$&&&&
%%%%&&&&
%%%%&&&&
''''''''
''''''''
''''''''
''''''''
``````

``````Āāăăąąąąćććććććć
ĂĂăăąąąąćććććććć
ĄĄĄĄąąąąćććććććć
ĄĄĄĄąąąąćććććććć
ĆĆĆĆĆĆĆĆćććććććć
ĆĆĆĆĆĆĆĆćććććććć
ĆĆĆĆĆĆĆĆćććććććć
ĆĆĆĆĆĆĆĆćććććććć
``````

``````一丁七七丅丅丅丅万万万万万万万万

``````

3

## C＃，239个185 182 180字节

C＃在较冗长的语言上一无所有。

``````using C=System.Console;
class P{
static void Main(string[]a){
for(int x,i,n=int.Parse(a[0]);n-->0;C.CursorTop=0)
for(i=1<<n,x=1<<n/2+n%2;i-->0;)
C.Write((char)(n+33)+(i%x<1?"\n":""));
}
}
``````

``````!"\$\$&&&&((((((((****************
##\$\$&&&&((((((((****************
%%%%&&&&((((((((****************
%%%%&&&&((((((((****************
''''''''((((((((****************
''''''''((((((((****************
''''''''((((((((****************
''''''''((((((((****************
))))))))))))))))****************
))))))))))))))))****************
))))))))))))))))****************
))))))))))))))))****************
))))))))))))))))****************
))))))))))))))))****************
))))))))))))))))****************
))))))))))))))))****************
``````

1

Bob

Hand-E-Food

2

# PERL，122个字符

``````\$N=<>;\$x=\$r=1;do{\$_=chr\$a+++65;\$s=\$x;\$o=\$_ x\$s;\$o.=\$_++x\$s,\$s*=2while\$N+65>ord++\$_;print"\$o\n"x\$r;\$r=\$x;\$x*=2}while++\$a<\$N
``````

``````\$N=<>;
\$x=\$r=1;
do{
\$_=chr\$a+++65;
\$s=\$x;
\$o=\$_ x\$s;
\$o.=\$_++x\$s,\$s*=2
while \$N+65>ord++\$_;
print "\$o\n"x\$r;
\$r=\$x;
\$x*=2
} while++\$a<\$N
``````

``````\$ echo 8 | perl pseudo-fractal.pl
ABDDFFFFHHHHHHHH
CCDDFFFFHHHHHHHH
EEEEFFFFHHHHHHHH
EEEEFFFFHHHHHHHH
GGGGGGGGHHHHHHHH
GGGGGGGGHHHHHHHH
GGGGGGGGHHHHHHHH
GGGGGGGGHHHHHHHH
``````

1

# PERL， 94   81个字符

``````\$N=\$_;\$_=\$:=A;\$h=1;++\$i%2?s/\$/\$:x\$h/gem:(\$_.=(\$/.\$:x2x\$h)x\$h,\$h*=2)while++\$:,--\$N
``````

``````\$N=\$_;
\$_=\$:=A;                    # \$: is current letter
\$h=1;

++\$i%2?
s/\$/\$:x\$h/gem:              # every odd run - add "columns"
(\$_.=(\$/.\$:x2x\$h)x\$h,\$h*=2) # every even run - add "rows"
while++\$:,--\$N              # iterate over letters
``````

``````\$ echo 8 | perl -p pseudo-fractal.fill.pl.5a5
ABDDFFFFHHHHHHHH
CCDDFFFFHHHHHHHH
EEEEFFFFHHHHHHHH
EEEEFFFFHHHHHHHH
GGGGGGGGHHHHHHHH
GGGGGGGGHHHHHHHH
GGGGGGGGHHHHHHHH
GGGGGGGGHHHHHHHH
``````

1

# 滑行，45个字符

``````가⓶貶上倘감雙⓶壹長⓸講增字⓶復⓷是標⓷各①合終并不⓶梴❸⓶疊合終不뀐標뀐并終終⓶丟各겠終
``````

## 带注释

``````for i in [0..n-1]
가⓶貶上
if (i != 0)
倘
i &= 1
감雙
e = list[0].Length
⓶壹長
c = ((char) (c[0] + 1)).Repeat(e)
⓸講增字⓶復
if (i)
⓷是
concatenate c onto every element of list
標⓷各①合終并
else
不
concatenate c.Repeat(list.Length) onto list
⓶梴❸⓶疊合
終
else (i.e., i == 0)
不
c = "A"
뀐
list = ["A"]
標뀐并
終

concatenate "\n" to every element in list
⓶丟各겠終
``````

1

### 没有缩进

``````var inp,j,i,x: integer;s:string;L:TStringlist;begin L:=TStringList.Create;readln(s);inp:=StrToIntDef(s,4);if inp<4then inp:=4;s:='';l.Add('AB');for I:=2to inp-1do begin j:=Length(L[0]);if i mod 2=0then for x:=0to L.Count-1do L.Add(s.PadLeft(j,Chr(65+i)))else for x:=0to L.Count-1do L[x]:=L[x]+s.PadLeft(j,Chr(65+i));end;Write(L.GetText);readln;end.
``````

### 带缩进

``````var
inp,j,i,x: integer;
s:string;
L:TStringlist;
begin
L:=TStringList.Create;
inp:=StrToIntDef(s,4);
if inp<4then inp:=4;
s:='';

for I:=2to inp-1do
begin
j:=Length(L[0]);
if i mod 2=0then
else
for x:=0to L.Count-1do
end;
Write(L.GetText);
end.
``````

1

# CJam，30（23）个字节

CJam比这项挑战还年轻几个月，因此没有绿色复选标记的资格。

``````l~(Sa1\${{_,I'!+*+}%z}fI\{z}*N*
``````

OP在注释中阐明，允许使用任何唯一的可打印字符集，因此我只是从头开始使用可打印的ASCII字符（在角落处有一个空格，`!`下一个等等）。

``````S]l~({{_,I'!+*+}%z}fIN*
``````