代码高尔夫:Mandelbrot集合

通常的代码高尔夫规则。 下面是以python为例的一个实现

from PIL import Image im = Image.new("RGB", (300,300)) for i in xrange(300): print "i = ",i for j in xrange(300): x0 = float( 4.0*float(i-150)/300.0 -1.0) y0 = float( 4.0*float(j-150)/300.0 +0.0) x=0.0 y=0.0 iteration = 0 max_iteration = 1000 while (x*x + y*y <= 4.0 and iteration < max_iteration): xtemp = x*x - y*y + x0 y = 2.0*x*y+y0 x = xtemp iteration += 1 if iteration == max_iteration: value = 255 else: value = iteration*10 % 255 print value im.putpixel( (i,j), (value, value, value)) im.save("image.png", "PNG") 

结果应该是这样的

Mandelbrot集合

允许使用图像库。 或者,您可以使用ASCII艺术。 这段代码也是一样的

 for i in xrange(40): line = [] for j in xrange(80): x0 = float( 4.0*float(i-20)/40.0 -1.0) y0 = float( 4.0*float(j-40)/80.0 +0.0) x=0.0 y=0.0 iteration = 0 max_iteration = 1000 while (x*x + y*y <= 4.0 and iteration < max_iteration): xtemp = x*x - y*y + x0 y = 2.0*x*y+y0 x = xtemp iteration += 1 if iteration == max_iteration: line.append(" ") else: line.append("*") print "".join(line) 

结果

 ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** **************************************** *************************************** **************************************** *************************************** **************************************** *************************************** **************************************** *************************************** **************************************** *************************************** **************************************** *************************************** **************************************** *************************************** *************************************** ************************************** ************************************* ************************************ ************************************ *********************************** *********************************** ********************************** ************************************ *********************************** ************************************* ************************************ *********************************** ********************************** ******************************** ******************************* **************************** *************************** ***************************** **************************** **************************** *************************** ************************ * * *********************** *********************** * * ********************** ******************** ******* ******* ******************* **************************** *************************** ****************************** ***************************** ***************************** * * * **************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** 

编辑

ASCII艺术规则:

  • 行/列的大小是参数化的,代码必须使用任何有效的值。
  • 至less有三级密度的差异取决于迭代计数(所以我的原型不符合)
  • 水平定向(所以我的原型不兼容)
  • 临界参数是固定的(最大迭代= 1000,失控值x x + y y≤4.0)

图表规则:

  • 行/列的大小是参数化的,代码必须使用任何有效的值。
  • 至less三个级别的颜色,灰度
  • 水平定向(我的原型是兼容的)

perlmonks已经在几年前发布了perl解决scheme,它写道:

 #!/usr/bin/perl $r=25; $c=80; $xr=6;$yr=3;$xc=-0.5;$dw=$z=-4/ 100;local$";while($q=$dr=rand() /7){$w+=$dw;$_=join$/,map{$Y=$_* $yr/$r; join"" ,map{$ x=$_*$ xr/$c;($ x,$y)= ($xc+$x *cos($ w)-$Y* sin$w,$yc+ $x*sin ($w)+$Y*cos $w);$ e=-1;$ a=$b=0 ;($a,$b) =($u-$v+$x,2*$a* $b+$y) while( $ u=$a*$ a)+($v=$b*$b)<4.5 &&++$e <15;if (($e>$ q&&$e< 15)||($e==$q and rand() <$dr)) {$q=$e;($d0,$d1) =($x,$ y); } chr(+( 32,96,+ 46,45,43,58,73,37 ,36,64 ,32)[$ e/1.5] );}(-$ c/2)..($c/2)-1;} (-$r/2 )..($ r/2)-1;select$", $",$", 0.015; system $^O=~m ~[wW]in~x?"cls": "clear";print ;$xc=( $d0+15 *$xc)/16;$yc=($ d1+15*$yc)/ 16;$_*= 1+$z for $xr,$yr;$dw *=-1 if rand ()<0.02; (++$i%110 )||($z*=-1)} 

这是一个“Mandelbrot探险家”。

(根据它的创build者,它旋转,放大和缩小,随机滚动查看它认为“有趣”的Mandelbrot集合的区域。)

它并不完全遵循这里命名的规格,而是做了一个有趣的条目(imho)。 也许一个简单的Mandlebrot对perl神不是很有趣; – )

问候

rboo

J,灰度级graphics输出,170个字符。

 load'viewmat' c=:>(<:;|:;0$])((2$>:@+:)$-:%~i:)300 (2.5*|:3 99$i._99)viewmat {:99&<.@;@(({:+4&<@:({.+1&{)@:*:);~(0{c)&+@({.-1&{)@:*:,:(1{c)&+@:+:@({.*1&{))^:99 c 

替代文字160wpb4.jpg

J,带有等级的graphics输出,151个字符。

 load'viewmat' c=:>(<:;|:;0$])((2$>:@+:)$-:%~i:)99 viewmat {:99&<.@;@(({:+4&<@:({.+1&{)@:*:);~(0{c)&+@({.-1&{)@:*:,:(1{c)&+@:+:@({.*1&{))^:99 c 

输出:

替代文字160wpb4.jpg

J,graphics输出,124个字符。

 load'viewmat' c=:>(<:;|:)((2$>:@+:)$-:%~i:)200 viewmat 4>:({.+{:)@:*:(5<.>@(({.c)&+@({.-{:)@:*:;({:c)&+@:+:@({.*{:)))^:999 c 

基本上只是在ascii输出上运行“viewmat”。

替代文字160wpb4.jpg

J,ASCII,101个字符。

 c=:>(<:;|:)((2$>:@+:)$-:%~i:)20 4>:({.+{:)@:*:(5<.>@(({.c)&+@({.-{:)@:*:;({:c)&+@:+:@({.*{:)))^:999 c 

浪费了6个字符来正确参数化大小。

J,ASCII,95个字符。

 c=:>(<:;|:)41 41$10%~i:20 4>:({.+{:)@:*:(5<.>@(({.c)&+@({.-{:)@:*:;({:c)&+@:+:@({.*{:)))^:999 c 

它不会执行多个灰度级别。

解释(目前过时,稍后更新):

 i:20 

生成从-20到20的整数列表。

 10%~i:20 

将它们全部除以10( %是除法, ~是参数的倒数顺序。

 41 41$10%~i:20 

把这个列表填入一个41×41数组中,并进行换行。

 (-&1;|:)41 41$`10%~i:20` 

追加到这个数组第二个相同大小的数组,但转置。 -&1从每个元素中减去一个; 是追加, |:是转置。 现在我们有一个2x41x41数组,其中第一个41×41数组包含每个坐标的“x0”值,第二个数组包含“y0”值。

 4<:~({.+{:)@:*:(5<.>@(({.c)&+@:({.-{:)@:*:;({:c)&+@:+:@:({.*{:)))^:1000 ($c)$0 

哇。 让我们从右边分解这个。

 ($c)$0 

这创build了第二个2x41x41arrays(与c大小相同),填充0。 这将是我们正在迭代的variables – 基本上,第一个数组包含“x”值,第二个包含“y”值。

^:1000表示“在括号中重复前面的事情1000次,这是我们的循环计数器。

 (5<.>@(({.c)&+@:({.-{:)@:*:;({:c)&+@:+:@:({.*{:)) 

这是下一个大块。 这基本上是做循环的一个迭代。 首先,我们用(({.c)&+@:({.-{:)@:*:然后join到y ({:c)&+@:+:@:({.*{:)

  (({.c)&+@:({.-{:)@:*: 

这会生成x(请记住它正在对代表x和y的2x41x41arrays进行操作)。 首先它正方形*:每个元素,然后是{. - {: {. - {:或x ^ 2 – y ^ 2。 {. select第一个41x41arrays和{:第二个。 @:一起joinfunction。

对于x ^ 2-y ^ 2,我们需要添加x0 – 这是c的第一个41x41arrays,所以我们可以用({.c)&+& curries {.c (x0)

 ({:c)&+@:+:@:({.*{:) 

我们以类似的方式生成y。 首先我们两两乘以inputx {. 和y {:数组,用+:加倍结果,并添加y0 {:c

这个函数的最后一步就是简单的将这两个新的x和y数组的连接进行拆箱,然后在5处进行上限,因为这个函数在4以上单调递增,如果我们不限制每次迭代的值,则限制整数。

 4>:({.+{:)@:*: 

最后一步,一旦我们完成迭代。 我们将x和y数组放在一起*: :,把它们加在一起{.+{: ,并且对于小于4的每个元素都做一个布尔数组。

输出:

 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

Python 108(是122):

 (900):print“\ nx”[(a%30> 0)+(abs(reduce(lambda z,c:z * z + c,[a%30 * .1-2 + 1j * (A / 30 * .1-1.5)] * 30))<2)],

最后的“30”是迭代计数,而不是维度之一。
输出看起来如此:

 。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  X 。  。  。  。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  xx。  。  。  。  。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  xx。  。  。  。  。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  。  。  。  。  。  。  X 。  xxxxx。  。  。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  。  。  。  。  。  。  xxxxxxxxx。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  。  。  。  。  。  xxxxxxxxxx。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  。  X 。  。  。  xxxxxxxxxx。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  xxx。  xxxxxxxxxxxx。  。  。  。  。 
 。  。  。  。  。  。  。  xxxxxxxxxxxxxxxx。  。  。  。  。  。 
 xxxxxxxxxxxxxxxxxxxxx x。  。  。  。  。  。  。 
 。  。  。  。  。  。  。  xxxxxxxxxxxxxxxx。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  xxx。  xxxxxxxxxxxx。  。  。  。  。 
 。  。  。  。  。  。  。  。  。  X 。  。  。  xxxxxxxxxx。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  。  。  。  。  。  xxxxxxxxxx。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  。  。  。  。  。  。  xxxxxxxxx。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  。  。  。  。  。  。  X 。  xxxxx。  。  。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  xx。  。  。  。  。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  xx。  。  。  。  。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  X 。  。  。  。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。 
 。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。  。

现在要根据更新的规则进行更新….

Haskell(185个字符,具有问题中所需的所有function)

使用复杂的数字,并实际计算所需的迭代次数(不像我的其他答案中的“简单”版本)。

 import Complex iv=show(length$takeWhile((<=4).magnitude)$take 1000$iterate(\c->c*c+v)v)!!0 rt=[-2,4/read t-2..2] main=getLine>>=(\[s,t]->mapM_ putStrLn[[i$x:+y|x<-rs]|y<-rt]).words 

从标准input读取结果图像的尺寸。 输出是根据所需迭代次数“彩色”的:

 $ ./fract
 60 30
 1111111111111111111111111111111111111111111111111111111111111
 1111111111111112222222222222222111111111111111111111111111111
 1111111112222222222222222222222222222111111111111111111111111
 1111112222222222222222222222222222222222111111111111111111111
 1112222222222222222222222222222222222222222111111111111111111
 1222222222222222222222333333333322222222222221111111111111111
 2222222222222222223333333344443333332222222222211111111111111
 2222222222222233333333344458755443333322222222222111111111111
 2222222222233333333344445568117544433333222222222211111111111
 2222222233333333344445556711111765544333322222222221111111111
 2222233333333444445562391112161568786443332222222222111111111
 2223333334444455556681111111111111157544333222222222211111111
 2333334445617677777911111111111111111854333222222222211111111
 3333444456681131231111111111111111111654333322222222221111111
 3444555671111111111111111111111111114644333322222222221111111
 2569888111111111111111111111111111296544333322222222221111111
 3444555671111111111111111111111111114644333322222222221111111
 3333444456681131231111111111111111111654333322222222221111111
 2333334445617677777911111111111111111854333222222222211111111
 2223333334444455556681111111111111157544333222222222211111111
 2222233333333444445562391112161568786443332222222222111111111
 2222222233333333344445556711111765544333322222222221111111111
 2222222222233333333344445568117544433333222222222211111111111
 2222222222222233333333344458755443333322222222222111111111111
 2222222222222222223333333344443333332222222222211111111111111
 1222222222222222222222333333333322222222222221111111111111111
 1112222222222222222222222222222222222222222111111111111111111
 1111112222222222222222222222222222222222111111111111111111111
 1111111112222222222222222222222222222111111111111111111111111
 1111111111111112222222222222222111111111111111111111111111111
 1111111111111111111111111111111111111111111111111111111111111

delphi – 310 249 239 224字符

ASCII版本。 使用7级渐变阴影。

  • 删除program P;{$APPTYPE CONSOLE}根据Uwe Raabe的build议);
  • 内联1000 const(由Uwe Raabebuild议);
  • 内联'8Oo;,. ' '8Oo;,. '可变的;
  • word改为integer以便循环variables可以是负数,然后将I的循环范围从3..38-5..30 ,使得(I-8)可以由I (由Eric Grangebuild议(I-8)replace;
  • 1000改为1e3 (由Eric Grangebuild议)
  • 改变typesDouble Real (由Luc Neville通过电子邮件build议)
  • while((x*x+y*y<=4)and(t<1000))do – > while(x*x+y*y<=4)and(t<1000)do Luc Neville通过电子邮件)
  • 删除了数字之间的关键字之后的空格(以便for j:=-5 to 30 do变为for j:=-5to 30do (由Neville通过电子邮件推荐)
  • 将循环范围更改for j:=8to 40do ,删除负号,并将整数更改为单词。 通过改变x * x - y * y + i / 16 - 2;补偿公式中的这个偏移量x * x - y * y + i / 16 - 2;x * x - y * y + i / 16 - 3 ;

不可读的版本:

 var n,x,y:Real;t,i,j:Word;begin for j:=8to 40do begin for i:=8to 65do begin x:=0;y:=0;t:=0;while(x*x+y*y<=4)and(t<1e3)do begin n:=x*xy*y+i/16-3;y:=2*x*y+j/12-2;x:=n;inc(t)end;Write('8Oo;,. '[t mod 7+1])end;WriteLn;end;end. 

格式化的代码:

 var n, x, y: Real; t, i, j: Word; begin for j := 8 to 40 do begin for i := 8 to 65 do begin x := 0; y := 0; t := 0; while (x * x + y * y <= 4) and (t < 1e3) do begin n := x * x - y * y + i / 16 - 3; y := 2 * x * y + j / 12 - 2; x := n; inc(t) end; Write('8Oo;,. '[t mod 7 + 1]) end; WriteLn; end; end. 

输出:

 OOOOOOOOOOOOOOOOOooooooooooooooooooooooooooooooooooooooooo OOOOOOOOOOOOOOOOooooooooo;;;;;;;;;;;;;;;oooooooooooooooooo OOOOOOOOOOOOOOOoooooo;;;;;;;;;;;;;;,,,,,;;;;oooooooooooooo OOOOOOOOOOOOOOooooo;;;;;;;;;;;;;,,,, ; .,,,;;;oooooooooooo OOOOOOOOOOOOOoooo;;;;;;;;;;;;;,,,,.. O ,,,,;;;oooooooooo OOOOOOOOOOOOooo;;;;;;;;;;;;;,,,,,...8oo,8..,,,;;;;oooooooo OOOOOOOOOOOooo;;;;;;;;;;;;,,,,,,.. Oo. ; 8...,,;;;;ooooooo OOOOOOOOOOOoo;;;;;;;;;;;;,,,,,. 8OO O8 ..,,;;;;oooooo OOOOOOOOOOoo;;;;;;;;;;;,,,,.. O,oO8oo ,OOoO88,.,;;;;ooooo OOOOOOOOOOo;;;;;;;;;;,,,.... o. . OOO ,;;;;;oooo OOOOOOOOOO;;;;;;;;;,,...... o., o .,;;;;;ooo OOOOOOOOOo;;;;;;,,. o 88O. ;O.,;;;;;ooo OOOOOOOOO;;;,,,,,.. ,,o;,oOo; o ,,;;;;;oo OOOOOOOOO;,,,,,... 8o; 8;, .,,;;;;;oo OOOOOOOOO,,,,,... Oo . 8.,,;;;;;oo OOOOOOOOO,.,. 88oo o , , .,,;;;;;oo OOOOOOOO ,8 .,,;;;;;;o OOOOOOOOO,.,. 88oo o , , .,,;;;;;oo OOOOOOOOO,,,,,... Oo . 8.,,;;;;;oo OOOOOOOOO;,,,,,... 8o; 8;, .,,;;;;;oo OOOOOOOOO;;;,,,,,.. ,,o;,oOo; o ,,;;;;;oo OOOOOOOOOo;;;;;;,,. o 88O. ;O.,;;;;;ooo OOOOOOOOOO;;;;;;;;;,,...... o., o .,;;;;;ooo OOOOOOOOOOo;;;;;;;;;;,,,.... o. . OOO ,;;;;;oooo OOOOOOOOOOoo;;;;;;;;;;;,,,,.. O,oO8oo ,OOoO88,.,;;;;ooooo OOOOOOOOOOOoo;;;;;;;;;;;;,,,,,. 8OO O8 ..,,;;;;oooooo OOOOOOOOOOOooo;;;;;;;;;;;;,,,,,,.. Oo. ; 8...,,;;;;ooooooo OOOOOOOOOOOOooo;;;;;;;;;;;;;,,,,,...8oo,8..,,,;;;;oooooooo OOOOOOOOOOOOOoooo;;;;;;;;;;;;;,,,,.. O ,,,,;;;oooooooooo OOOOOOOOOOOOOOooooo;;;;;;;;;;;;;,,,, ; .,,,;;;oooooooooooo OOOOOOOOOOOOOOOoooooo;;;;;;;;;;;;;;,,,,,;;;;oooooooooooooo OOOOOOOOOOOOOOOOooooooooo;;;;;;;;;;;;;;;oooooooooooooooooo OOOOOOOOOOOOOOOOOooooooooooooooooooooooooooooooooooooooooo 

T-SQL( 421 408个字符)

 declare @s varchar(max); with x(x)as(select CAST(-2.0 as real)union all select x+.01 from x where x<1), y(y)as(select CAST(-1.1 as real)union all select y+.02 from y where y<1.1), g(x,y,u,v,g)as(select x,y,x*0,y*0,0 from x,y union all select x,y,u*uv*v+x,2*u*v+y,g+1 from g where g<24and u*u+v*v<4), m(x,y,v)as(select x,y,case when x<-1.99 then char(10)end+substring(' .-''^"+oiexp**##$$$§§%%%@',COUNT(*),1)from g group by x,y) select @s=@s+v from m order by y,x option(maxrecursion 400) select @s 

输出在这里:

awk – 134 135个字符

ASCII艺术,完全符合。 相当简单的python参考实现的翻译:

 {for(j=-2;j<=2;j+=4/$2){for(i=-3;i<=1;i+=4/$1){for(x=y=k=0;x*x+y*y<=4&&++k<4^5;) {t=x*xy*y+i;y=2*x*y+j;x=t}printf"%d",log(k)}print""}} 

testing运行

 $ awk -f mandel.awk 10 10 00000000000 00000000000 00000111000 00001116110 00011166610 00046666611 00011166610 00001116110 00000111000 00000000000 00000000000 

这是一个VT-100艺术。 将xterm设置为“不可读”字符,然后尝试一个400×200的设置:

 {for(j=-2;j<=2;j+=4/$2){for(i=-3;i<=1;i+=4/$1){for(x=y=k=0;x*x+y*y<=4&&++k<1000;) {t=x*xy*y+i;y=2*x*y+j;x=t}printf"\x1b[4%dm ",log(k)}print"\x1b[0m"}} 

Haskell(162个字符)

一个(相当)直接的ASCII艺术版本:

 c(x,y)|x*x+y*y<4.0='x' |True='.' ivw=c(iterate s(v,w)!!1000)where s(x,y)=(x*xy*y+v,2*x*y+w) main=mapM_ putStrLn[[ixy|x<-[-1.5,-1.45..0.5]]|y<-[1,0.9.. -1]] 

输出:

 $ ./a.out
 .........................................
 .........................................
 .......................... XXXX ...........
 .......................... XXXX ...........
 .................... x..xxxxxxxxxx ........
 .................... xxxxxxxxxxxxxxxxx ....
 .................. xxxxxxxxxxxxxxxxxxx ....
 ................. xxxxxxxxxxxxxxxxxxxxx ...
 ....... xxxxxxx..xxxxxxxxxxxxxxxxxxxxxx ...
 ...... xxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxx ...
 ..xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx .....
 ...... xxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxx ...
 ....... xxxxxxx..xxxxxxxxxxxxxxxxxxxxxx ...
 ................. xxxxxxxxxxxxxxxxxxxxx ...
 .................. xxxxxxxxxxxxxxxxxxx ....
 .................... xxxxxxxxxxxxxxxxx ....
 .................... x..xxxxxxxxxx ........
 .......................... XXXX ...........
 .......................... XXXX ...........
 .........................................
 .........................................

更可读的版本:

 outchar (x,y) | x*x + y*y < 4.0 = 'x' | otherwise = '.' calc vw = outchar (iterate step (v,w) !! 1000) where step (x,y) = (x*x - y*y + v, 2*x*y + w) main = mapM_ putStrLn [[calc xy | x <- [-1.5, -1.45 .. 0.5]] | y <- [1, 0.9 .. -1]] 

python 197 162

 def m(): for a in range(900): c=complex(a%30*.1-2,a/30*.1-1.5);z,i=cc,0 while i<28 and abs(z)<2:z,i=z*z+c,i+1 if a%30==0:print print ".-+oxawOX "[i/3], 

我对如何摆脱python中的空白感兴趣。

汇编

.COM可执行文件= 140个字节

源= 652字节

 mov ax,13h int 10h mov bx,200 xor di,di mov ax,0a000h mov es,ax l1:mov bp,320 mov [si],bx fild w[si] fisub w[v100] fidiv w[v50] l2:mov cx,1000 mov [si],bp fild w[106h] fisub w[si] fidiv w[v80] fld1 fsubp fldz fldz l3:fld st(1) fmul st(0) fld st(1) fmul st(0) fld st(0) fadd st(2) fcomp d[v4] fstsw ax test ah,45h jz l4 fsubp fadd st(3) fxch st(2) fild w[v2] fmulp st(1) fmulp st(1) fadd st(3) loop l3 mov al,255 l5:fcompp fcomp stosb dec bp jnz l2 fcomp dec bx jnz l1 mov ah,7 int 21h mov ax,3 int 10h ret l4:mov ax,-10 mul cx fcompp jmp l5 v100:dw 100 v50:dw 80 v80:dw 90 v4:dd 4.0 v2:dw 2 

JavaScript(168/174个字符)

犀牛版(168个字符):

 m=1000;for(i=0;i<40;i++){l=[];for(j=0;j<80;j++){v=j/80*3-2,w=2-i/40*3,x=y=c=0;while(x*x+y*y<5&&c<m)t=x*xy*y+v,y=2*x*y+w,x=t,c++;l.push(c==m?' ':'-')}print(l.join(''))} 

Firebug版本(174个字符):

 m=1000;for(i=0;i<40;i++){l=[];for(j=0;j<80;j++){v=j/80*3-2,w=2-i/40*3,x=y=c=0;while(x*x+y*y<5&&c<m)t=x*xy*y+v,y=2*x*y+w,x=t,c++;l.push(c==m?' ':'-')}console.log(l.join(''))} 

和一个dcinput – 152个字符

我一直在疯狂的dc

 Ak?4r/sa4r/sbA00sm[0*]sG_2sj[_3si[0ddsxsysk[lxd*lyd*-li+2lxly**lj+sysx1lxd*lyd*+ 4!>G1lk1+dsklm<G*1=L]dsLx0klk1-vvnAklila+dsi1!<I]dsIxAPljlb+dsj2!<J]dsJx 

testing运行:

 bash-3.2$ dc -f mandel.dc 10 20 000000000000000000000 000000000011111111111 000000001111111111111 000000111111115211111 000000111111555551111 000000555555555551111 000000111111555551111 000000111111115211111 000000001111111111111 000000000011111111111 000000000000000000000 

ruby – 139个字符(Twitter的友好)

 b,a=$*;a.to_i.times{|l|puts (0..b.to_i).map{|n|x=y=i=0;(x,y,i=x*xy*y+n/38.0-1.5,2*x*y+l/14.0-1,i+1)until(x*x+y*y>4||i>78);(32+i).chr}*""} 

$ ruby mandelbrot.rb 80 32

或作为一个单一的命令行(134个字符,包括ruby -e

 ruby -e "32.times{|l|puts (0..78).map{|n|x=y=i=0;(x,y,i=x*xy*y+n/38.0-1.5,2*x*y+l/14.0-1,i+1)until(x*x+y*y>4||i>78);(32+i).chr}*''}" 
 “############################### $$$$$$$$$$$ %%%% &&“) * /))*。O&%$$$$$$$$ ######## “” “””
 ############################ $$$$$$$$$$$$$ %%%%%& ''( (* -G *('&& %% $$$$$$$$$ ######## “”
 ######################### $$$$$$$$$$$$$ %%%%% &&“929-03ooL。+ 0:'&%%%%% $$$$$$$ ########
 ##################### $$$$$$$$$$$$$$ %%% &&&&& ''() -  1oooooooo / *('&& %%%%%%% $$$$$ ######
 ################## $$$$$$$$$$$$ %%%& '' '' '' '''())*,6oooooooo。 *)(( '' &&&&&&&&%$$$ #####
 ############### $$$$$$$$$ %%%%%% &&'(+ 3:?0,++ ooE6ooooooooooo 8o1j 8)((( ()4 /'&%$$$ ###
 ########### $$$$$$ %%%%%%%%%% &&&& ''(* 1> ooo8oooooooooooooooooooooooo.3oooD /,'%% $$$ ##
 ####### $$$$ %%%%%%%%%%%%% &&&&&& ')8,17ooooooooooooooooooooooooooooooooQ0)' && %% $$$#
 $$$$$$%)(&&&&&&&&&&&&&&& '' '((* 18oooooooooooooooooooooooooooooooooooool *((' &%% $$$
 $$ %%%% && * 2 *))((((25 *(( '''((()+ F> = oooooooooooooooooooooooooooooooooooooooo1。(%% $$$
 %%%%% &&“()*,1o47 // 5o5 /?,+ *** + 3oooooooooooooooooooooooooooooooooooooooooo。)(&%% $$$
 %%%%& '''(* +  -  3ooooooooooom //  -  oooooooooooooooooooooooooooooooooooooooooooo9 + %% $$$
 &&(* +)))+  - ?ooooooooooooooooL5ooooooooooooooooooooooooooooooooooooooooooo8)%%% $$$
 '()*  -  X = U95ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo *' && %%% $$$
 ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo:+)('&& %%% $$$
 '()*  -  X = U95ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo *' && %%% $$$
 &&(* +)))+  - ?ooooooooooooooooL5ooooooooooooooooooooooooooooooooooooooooooo8)%%% $$$
 %%%%& '''(* +  -  3ooooooooooom //  -  oooooooooooooooooooooooooooooooooooooooooooo9 + %% $$$
 %%%%% &&“()*,1o47 // 5o5 /?,+ *** + 3oooooooooooooooooooooooooooooooooooooooooo。)(&%% $$$
 $$ %%%% && * 2 *))((((25 *(( '''((()+ F> = oooooooooooooooooooooooooooooooooooooooo1。(%% $$$
 $$$$$$%)(&&&&&&&&&&&&&&& '' '((* 18oooooooooooooooooooooooooooooooooooool *((' &%% $$$
 ####### $$$$ %%%%%%%%%%%%% &&&&&& ')8,17ooooooooooooooooooooooooooooooooQ0)' && %% $$$#
 ########### $$$$$$ %%%%%%%%%% &&&& ''(* 1> ooo8oooooooooooooooooooooooo.3oooD /,'%% $$$ ##
 ############### $$$$$$$$$ %%%%%% &&'(+ 3:?0,++ ooE6ooooooooooo 8o1j 8)((( ()4 /'&%$$$ ###
 ################## $$$$$$$$$$$$ %%%& '' '' '' '''())*,6oooooooo。 *)(( '' &&&&&&&&%$$$ #####
 ##################### $$$$$$$$$$$$$$ %%% &&&&& ''() -  1oooooooo / *('&& %%%%%%% $$$$$ ######
 ######################### $$$$$$$$$$$$$ %%%%% &&“929-03ooL。+ 0:'&%%%%% $$$$$$$ ########
 ############################ $$$$$$$$$$$$$ %%%%%& ''( (* -G *('&& %% $$$$$$$$$ ######## “”
 “############################### $$$$$$$$$$$ %%%% &&“) * /))*。O&%$$$$$$$$ ######## “” “””
 “” “”“############################### $$$$$$$$$ %%%&” *)'&& %%% $$$$$$$ ####### “” “” “” “””
 “” “” “” “”“################################# $$$$$$$% %%%% $$$$$ ######### “” “” “” “” “” “””
 “” “” “” “” “” “” “” “” ################################## ########### “” “” “” “” “” “” “” “” “” “” 

python。 98个字符。

 for _ in range(526):z=0;exec"z=z*z+_%25*.1-2+_/25*.1j-1j;"*50;print[".#"[z.real<4],"\n"][_%25<1], 

打印这样的东西:

 . . . . . . . . . . . . . . . . . . . # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # # . . . . . . . . . . . . . . . . . . . . . . # # . . . . . . . . . . . . . . . . . . . # . # # # # # . . . . . . . . . . . . . . . . . # # # # # # # # # . . . . . . . . . . . . . . # # # # # # # # # # . . . . . . . . . . . . . . # # # # # # # # # # . . . . . . . . . # # # . # # # # # # # # # # # . . . . . . . . # # # # # # # # # # # # # # # # . # # # # # # # # # # # # # # # # # # # # # # . . . . . . . . . # # # # # # # # # # # # # # # # . . . . . . . . . # # # . # # # # # # # # # # # . . . . . . . . . . . . . . # # # # # # # # # # . . . . . . . . . . . . . . # # # # # # # # # # . . . . . . . . . . . . . . . # # # # # # # # # . . . . . . . . . . . . . . . # . # # # # # . . . . . . . . . . . . . . . . . . . . # # . . . . . . . . . . . . . . . . . . . . . . # # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . 

http://codepad.org/rNPrgQ3H

C# – 330

如果您放弃使用语句,并删除前导空格和行结尾

 int c,i,j,w=300,h=300,m=50; using(var b=new Bitmap(w,h)){ for(i=0;i<w;i++){ for(j=0;j<h;j++){ double x0=4.0*(iw/2)/w-1,y0=4.0*(jh/2)/h,x=0.0,y=0.0; for(c=0;x*x+y*y<=4.0&&c<m;c++){ var t=x*xy*y+x0; y=2.0*x*y+y0;x=t; } int v=c==m?255:c*10%255; b.SetPixel(i,j,Color.FromArgb(v,v,v)); } } } 

不用长时间logging设置 – 但是从Python示例源代码转换并且压缩超出可读性的乐趣。