Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Your task is to draw the mandelbrot set in ascii. It should look something like enter image description here

The complex number 'C' lies in the mandelbrot set, when the function z = z^2 + c remains bounded, z starts at 0. For us, the point lies in the set if |z| < 2 (: abs(z) < 2) after 32 iterations of z = z*z + c, starting at z = 0.

Plot the mandelbrot set on the complex plane from (-2 - i) to (1 + i), and a minimum resolution of 40x30, using ascii characters in your favourite language, using as few characters as possible.

share|improve this question
17  
Since the specification is a little bit unclear with respect to that point I can propose the following low-res ;-) 1-char php solution: * –  Howard Jul 6 '11 at 17:32
    
Or monochromatic ......................... –  Alexandru Jul 6 '11 at 18:04
3  
Well I was hoping I could just say "don't be a jerk" :D. We'll go with at least 40x30 then. –  Hannesh Jul 6 '11 at 18:40
3  
I have a personal preference for tasks that solve a class of problems rather than one instance. Making the region to use an input would makes this questions qualify. In any case, the specification is a bit light. In the future you can get help with these kinds of issues on the meta sandbox or the puzzle lab chat before you task goes live –  dmckee Jul 6 '11 at 19:16
1  
@Hannesh, I agree with dmckee. If you change the question, I'll be happy to add arguments. –  boothby Jul 7 '11 at 0:01

22 Answers 22

up vote 33 down vote accepted

Assuming machine code counts, I wrote a prod a while back that generates a 320x200 color Mandelbrot in 64 bytes - http://www.pouet.net/prod.php?which=53287

Screenshot

Here is the code:

; "Microbrot" by Sir_Lagsalot

org 100h
mov al,13h
int 10h

les ax,[bx]

FillLoop:
cwd
mov ax,di
mov cx,320
div cx
sub ax,100
dec dh

xor bx,bx
xor si,si

MandelLoop:
mov bp,si
imul si,bx
add si,si
imul bx,bx
jo MandelBreak
imul bp,bp
jo MandelBreak
add bx,bp
jo MandelBreak
sub bx,bp
sub bx,bp

sar bx,6
add bx,dx
sar si,6
add si,ax

loop MandelLoop

MandelBreak:
xchg ax,cx
stosb
jmp FillLoop

Compiled version in base64:

sBPNEMQHmYn4uUAB9/GD6GT+zjHbMfaJ9Q+v8wH2D6/bcBkPr+1wFAHrcBAp6ynrwfsGAdPB/gYBxuLbkarrxg==
share|improve this answer
4  
I read the code and thought it was way to short/simple to do anything interesting. 2 minutes later after sudo apt-get install dosbox; dosbox ./Microbrot.com I was found picking my jaw up from the floor. This is pretty darn impressive! –  sehe Dec 2 '11 at 0:36
2  
IMO we have a winner. –  Łukasz Niemier Jan 15 '12 at 10:34
    
Oh wow, I only just saw the code now. That is crazy! –  Hannesh May 21 '12 at 12:41

Common lisp -- 195 chars

(loop for y from -1 to 1 by 1/15 do
  (loop for x from -2 to 1 by .04 do
    (let*((c 126) (z (complex x y)) (a z))
      (loop while (< (abs (setq z (+ (* z z) a))) 2)
            while (> (decf c) 32)) 
      (princ (code-char c))))
  (terpri))

Tested with sbcl and clisp. Result:

~~~~~~~~~~~~~}}}}}}}}}}}}}}}}}}}}||||||||{{{zyvrwum{|||||}}}}}}~~~~~~~~~~~~~
~~~~~~~~~~~}}}}}}}}}}}}}}}}}}}}|||||||||{{{zyxvptwyz{{|||||}}}}}}~~~~~~~~~~~
~~~~~~~~~}}}}}}}}}}}}}}}}}}}}|||||||||{{{{zwLtb huwx{{{{||||}}}}}}}~~~~~~~~~
~~~~~~~~}}}}}}}}}}}}}}}}}}}|||||||||{{zzzyxvn    Knwyz{{{{||||}}}}}}~~~~~~~~
~~~~~~~}}}}}}}}}}}}}}}}}}||||||||{{zzzzyyywuk     qwxyzzzz{{|||}}}}}}~~~~~~~
~~~~~}}}}}}}}}}}}}}}}}}|||||||{{{zxjnpwwtjsqpi   lqrujnxyyxrz{|}}}}}}}}~~~~~
~~~~}}}}}}}}}}}}}}}}}|||||{{{{{zzzxt>  qf             pttfqeqz{|}}}}}}}}~~~~
~~~~}}}}}}}}}}}}}}}|||{{{{{{{{zzzxwup                      sxz{||}}}}}}}~~~~
~~~}}}}}}}}}}}}|||{z{{{{{{{zzzzywkmo                      rwyz{{||}}}}}}}~~~
~~}}}}}}}}}||||{{zwvyyyyyyyyyyyxvsP                        swvz{||}}}}}}}}~~
~~}}}}|||||||{{{zzwrtsww^uwwxxwvr                            iz{|||}}}}}}}~~
~}}}|||||||{{{{{zyxws  mj Ubhuutl                           sxz{|||}}}}}}}}~
~}||||||||{{{{{zyytun         qq                            avz{|||}}}}}}}}~
~|||||||{{zzzyxsvvum           j                            Sz{{|||}}}}}}}}~
~{{{{{yyzzzyyxwtbUP                                        qyz{{||||}}}}}}}~
~                                                        pvxyz{{||||}}}}}}}}
~{{{{{yyzzzyyxwtbUP                                        qyz{{||||}}}}}}}~
~|||||||{{zzzyxsvvum           j                            Sz{{|||}}}}}}}}~
~}||||||||{{{{{zyytun         qq                            avz{|||}}}}}}}}~
~}}}|||||||{{{{{zyxws  mj Ubhuutl                           sxz{|||}}}}}}}}~
~~}}}}|||||||{{{zzwrtsww^uwwxxwvr                            iz{|||}}}}}}}~~
~~}}}}}}}}}||||{{zwvyyyyyyyyyyyxvsP                        swvz{||}}}}}}}}~~
~~~}}}}}}}}}}}}|||{z{{{{{{{zzzzywkmo                      rwyz{{||}}}}}}}~~~
~~~~}}}}}}}}}}}}}}}|||{{{{{{{{zzzxwup                      sxz{||}}}}}}}~~~~
~~~~}}}}}}}}}}}}}}}}}|||||{{{{{zzzxt>  qf             pttfqeqz{|}}}}}}}}~~~~
~~~~~}}}}}}}}}}}}}}}}}}|||||||{{{zxjnpwwtjsqpi   lqrujnxyyxrz{|}}}}}}}}~~~~~
~~~~~~~}}}}}}}}}}}}}}}}}}||||||||{{zzzzyyywuk     qwxyzzzz{{|||}}}}}}~~~~~~~
~~~~~~~~}}}}}}}}}}}}}}}}}}}|||||||||{{zzzyxvn    Knwyz{{{{||||}}}}}}~~~~~~~~
~~~~~~~~~}}}}}}}}}}}}}}}}}}}}|||||||||{{{{zwLtb huwx{{{{||||}}}}}}}~~~~~~~~~
~~~~~~~~~~~}}}}}}}}}}}}}}}}}}}}|||||||||{{{zyxvptwyz{{|||||}}}}}}~~~~~~~~~~~
~~~~~~~~~~~~~}}}}}}}}}}}}}}}}}}}}||||||||{{{zyvrwum{|||||}}}}}}~~~~~~~~~~~~~

Slightly modified from B. Clementson blog.

share|improve this answer
    
This is code golf. Don't count indentation if it isn't needed. –  J B Sep 29 '11 at 8:06
    
@ JB. I updated the char count. It does not take superfluous spaces into account anymore. I have left the code indented for readability. I also tuned a parameter, the image now follows the size specification. –  stackman Sep 29 '11 at 19:18
    
Much better. Upvoted. –  J B Sep 29 '11 at 20:44

Python, 146 145 143char

z=lambda x,c,n:z(x**2+c,c,n-1)if n*(abs(x)<2)else x
for y in range(-15,16):print''.join(' @'[abs(z(0,x/25.+y/15j,32))<2]for x in range(-50,26))

Had to add the clause (abs(x)<2) to the conditional expression to keep Python from winging about overflows. But... this is a reason I love Sage...

Sage, 133char

z=lambda x,c,n:z(x^2+c,c,n-1)if n else abs(x)<2
for y in range(-15,16):
 print''.join(' +'[z(0,x/25+y/15j,32)]for x in range(-50,26))

Sample output (from python version)

                                                  @                         

                                            @  @                            
                                             @@@@@                          
                                             @@@@@                          
                                              @@@                           
                                    @@@  @@@@@@@@@@@@@                      
                                     @@@@@@@@@@@@@@@@@@@@@@                 
                                    @@@@@@@@@@@@@@@@@@@@@@                  
                                  @@@@@@@@@@@@@@@@@@@@@@@@@                 
                        @        @@@@@@@@@@@@@@@@@@@@@@@@@@@@               
                     @@  @@      @@@@@@@@@@@@@@@@@@@@@@@@@@@                
                     @@@@@@@@@  @@@@@@@@@@@@@@@@@@@@@@@@@@@@                
                    @@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@               
                 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                 
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                   
                 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                 
                    @@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@               
                     @@@@@@@@@  @@@@@@@@@@@@@@@@@@@@@@@@@@@@                
                     @@  @@      @@@@@@@@@@@@@@@@@@@@@@@@@@@                
                        @        @@@@@@@@@@@@@@@@@@@@@@@@@@@@               
                                  @@@@@@@@@@@@@@@@@@@@@@@@@                 
                                    @@@@@@@@@@@@@@@@@@@@@@                  
                                     @@@@@@@@@@@@@@@@@@@@@@                 
                                    @@@  @@@@@@@@@@@@@                      
                                              @@@                           
                                             @@@@@                          
                                             @@@@@                          
                                            @  @                            

                                                  @                         
share|improve this answer
    
I think you can just use 15j in the python version too –  gnibbler Jul 8 '11 at 4:48
    
To shave one character add line r=range(-50,26). Then replace range(-15,16) with r[35:66] and replace range(-50,26) with r. –  Steven Rumbalski Sep 30 '11 at 17:51

J, 61 characters

{&' *'(2:>[:|([+]*])^:32 ::_:)&0"0(j.1-16%~i.33)+/_2+32%~i.97
                                                                *                                

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

                                                                *                                

55 for space-separated 0/1 instead of stars.

(2:>[:|([+]*])^:32 ::_:)&0"0(j.1-16%~i.33)+/_2+16%~i.49
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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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ernador Jun 18 '12 at 21:19

Ruby, 95 characters

puts (-20..20).map{|y|(-40..20).map{|x|z=0;32.times{z=z*z+Complex(x,y)/2e1};z.abs<2??*:' '}*''}

Sample output:

                                        *                    

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

                                        *                    
share|improve this answer

Haskell, 130

import Complex
main=mapM_ putStrLn[[" *"!!fromEnum(magnitude(iterate((+(x:+y)).(^2))0!!32)<2)|x<-[-2,-1.95..1]]|y<-[-1,-0.95..1]]

Output:

                                        *                    

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

                                        *          
share|improve this answer
    
Above my head is full of star****** –  Jamie Apr 26 at 9:11

Perl, 153 chars

for(-21..20){$y=$_/20;for(-60..18){$r=($x=$_/30);$i=$y;for(1..99){$t=$r;$r=$r**2-$i**2+$x;$i=$t*$i*2+$y}if($r**2+$i**2<4){print"X"}else{print$"}}print$/}

Output: I can't post a picture because I am a new user, so I will try posting the text of the output.

                                                            X                  


                                                        XX                     
                                                      XXXXXX                   
                                                     XXXXXXX                   
                                                      XXXXX                    
                                                   X X XX X                    
                                            XX   XXXXXXXXXXXXXXXX              
                                            XXXXXXXXXXXXXXXXXXXXXXXXXX         
                                            XXXXXXXXXXXXXXXXXXXXXXXXXX         
                                          X XXXXXXXXXXXXXXXXXXXXXXXXXX          
                                          XXXXXXXXXXXXXXXXXXXXXXXXXXXXX        
                                       XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX      
                                        XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX        
                          X XXXX       XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX       
                          XXXXXXXXX    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX       
                        XXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX       
                        XXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX        
                    XX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX        
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX           
                    XX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX        
                        XXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX        
                        XXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX       
                          XXXXXXXXX    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX       
                          X XXXX       XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX       
                                        XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX        
                                       XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX      
                                          XXXXXXXXXXXXXXXXXXXXXXXXXXXXX        
                                         X XXXXXXXXXXXXXXXXXXXXXXXXXX          
                                            XXXXXXXXXXXXXXXXXXXXXXXXXX         
                                            XXXXXXXXXXXXXXXXXXXXXXXXXX         
                                            XX   XXXXXXXXXXXXXXXX              
                                                   X X XX X                    
                                                      XXXXX                    
                                                     XXXXXXX                   
                                                      XXXXXX                   
                                                        XX                     


                                                            X                  
share|improve this answer

Here's a coffee-script answer running on node.js: In black and white:

m=(x,y)->
 a=x
 b=y
 z=0
 for i in [0..99]
  (return if i>60 then '*' else if i>10 then '-' else if i>5 then '.' else ' ') if z>4
  l=y*y
  z=x*x+l
  y=2*x*y+b
  x=x*x-l+a
 '@'
console.log (m x,y for x in [-1.5..0.5] by 2/79).join '' for y in [-1.3..1.3] by 2.6/40

ascii_mandel_color

Adding color:

n='\u001b[0m'
m=(x,y)->
 a=x
 b=y
 z=0
 for i in [0..999]
  (return if i>100 then '\u001b[33m*'+n else if i>10 then '\u001b[34m-'+n else if i>5 then '\u001b[31m.'+n else ' ') if z>4
  l=y*y
  z=x*x+l
  y=2*x*y+b
  x=x*x-l+a
 '\u001b[32m@\u001b[0m'
console.log (m x,y for x in [-1.5..0.5] by 2/79).join '' for y in [-1.3..1.3] by 2.6/40
share|improve this answer
    
Do you know looking at green is good for your eyes? –  Jamie Apr 26 at 9:11

Mathematica 56

RegionPlot[Abs@Nest[#^2+x+I*y&,0,9]<2,{x,-2,1},{y,-1,1}]

Mathematica 77

ArrayPlot[2^-Abs@Nest[#^2+Table[j+i*I,{i,-1.2,1.2,.1},{j,-1.8,0.6,.1}]&,0,6]]

enter image description here

Mathematica 77

Grid@Table[If[Abs@Nest[#^2+y+x*I&,0,30]<2,"*",""],{x,1,-1,-.1},{y,-2,0.5,.1}]

enter image description here

share|improve this answer

Haskell: 340 char

Well, as I see no haskell answer, I post mine, I tried to minimize it from what I have done so far. I am sure I can reduce it a lot. But here is the first try:

m (x,y) (z,t)=(z*x-y*t,y*z+x*t);
a (x,y) (z,t)=(x+z,y+t);
r=1.0
f c z 0=z
f c z n=f c (a (m z z) c) (n-1)
e (x,y)=sqrt(x*x+y*y)
t c=(e(f c (0.0,0.0) 32)) < 2
b=map (\z -> (t z, (fst z > r-0.01))) [(x,y) | y <- [-r,-r+(1.0/15)..r], x<-[-2*r,-1.96..r]]
s True="\n"
s _=""
g (b,c)=(if (b) then "@" else " ")++s c
main=putStrLn$concat$map g b

And here is the result:

                                                  @                         

                                            @  @                            
                                             @@@@@                          
                                             @@@@@                          
                                              @@@                           
                                    @@@  @@@@@@@@@@@@@                      
                                     @@@@@@@@@@@@@@@@@@@@@@                 
                                    @@@@@@@@@@@@@@@@@@@@@@                  
                                  @@@@@@@@@@@@@@@@@@@@@@@@@                 
                        @        @@@@@@@@@@@@@@@@@@@@@@@@@@@@               
                     @@  @@      @@@@@@@@@@@@@@@@@@@@@@@@@@@                
                     @@@@@@@@@  @@@@@@@@@@@@@@@@@@@@@@@@@@@@                
                    @@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@               
                 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                 
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                   
                 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                 
                    @@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@               
                     @@@@@@@@@  @@@@@@@@@@@@@@@@@@@@@@@@@@@@                
                     @@  @@      @@@@@@@@@@@@@@@@@@@@@@@@@@@                
                        @        @@@@@@@@@@@@@@@@@@@@@@@@@@@@               
                                  @@@@@@@@@@@@@@@@@@@@@@@@@                 
                                    @@@@@@@@@@@@@@@@@@@@@@                  
                                     @@@@@@@@@@@@@@@@@@@@@@                 
                                    @@@  @@@@@@@@@@@@@                      
                                              @@@                           
                                             @@@@@                          
                                             @@@@@                          
                                            @  @                            

                                                  @                         

OK - Inspired by some animated obfuscated C code on HN, here is an animated version:

a=27;b=79;c=C(-2.0,-1.0);d=C(1.0,1.0);e=C(-2.501,-1.003)
newtype C = C (Double,Double) deriving (Show,Eq)
instance Num C where C(x,y)*C(z,t)=C(z*x-y*t,y*z+x*t);C(x,y)+C(z,t)=C(x+z,y+t);abs(C(x,y))=C(sqrt(x*x+y*y),0.0)
r(C(x,y))=x;i(C(x,y))=y
f :: C -> C -> Int -> Int
f c z 0=0;f c z n=if(r(abs(z))>2)then n else f c ((z*z)+c) (n-1)
h j k = map (\z->(f (C z) (C(0,0)) 32,(fst z>l - q/2))) [(x,y)|y<-[p,(p+((o-p)/a))..o],x<-[m,(m + q)..l]] where o=i k;p=i j;m=r j;l=r k;q=(l-m)/b
u j k = concat $ map v $ h j k where v (i,p)=(" .,`'°\":;-+oO0123456789=!%*§&$@#"!!i):rst p;rst True="\n";rst False=""
main = putStrLn $ im 0 where cl n (C (x,y))=let cs=(1.1**n-1) in C ((x+cs*(r e))/cs+1,(y+cs*(i e))/cs+1);bl n=cl n c;tr n=cl n d;im n=u (bl n) (tr n)++"\x1b[H\x1b[25A"++im (n+1)

Copy/paste, do a runghc mandel.hs, enjoy!

Here is the kind of result after 50 iterations:

77777777777777777777777777777777777777777777777666666666666666666666666666666666
77777777777777777777777777777777777777777766665555555555566666666666666666666666                                                                                                     
666777777777777777777777777777666666666665543;4445555555555555555555666666666555
66666666666666666666666666666666666666555554300334555555555555555555555555555555 
6666666666666666666666666666666666665555554431:°33345555555555555555555555555544
5566666666666666666666666666666666555555554321 ;00O:3455555555555555555444444444
5555666666666666666666666666666655555555554O+++ :o022334444444444444444444444444
5555556666666666666666666666665555555555543210O-+O112333344444444444444444444444
55555555666666666666666666665555555555444333210o`O012333333444444444444444444444
4555555555566666666666666555555555544444333331O+°°,'0233333334444444444444444433
44444445555555556666555555555444444444433333210o-:O01122333333334444444444443333
44444444444444445555444444444444444444333332211O+ -o1112222223333333344433333222
444444444444433331133334444444444444433332221110o"+O0111222222222222222222222222  
34444444443333330OO03333334444444443332222221100O+-oO001122222222221110-O1111122
22333333333332210--01223333333333322222222211000o-°+o00000122222111110o°;o001111
11OO112222222111O;;O111222222211OO111122211000Oo-" :+ooOOOO.O0000000OOo'°oOO0000
0O;+O01122211000O--O00011221110O+;O00000OO +oooo-: :-+oo++";oOO0000Ooo+;;+oooO00
o+"+oO00OO OOOOoo::ooOOOO°OO00Oo+"+ooOooo+;°---",' ,,";--: ;-+oo+ +++;;°°;;-++:;
,° °':°: ` "`".°°  °° "°".  :'",  '°`°":`°` ,,``     .   . .°°'°° ` ..     `'°. 
+-`-oo+oo+'+o+`--°°;-`+o+"+oo+oo-'-++;+++-:,:::"`    °::°° :-;;--,;-; "  " ;-;":
OO"-O0000000000Oo--oO0000000000O-:oO0000Oo::+++;;: ":"-++-';+oooOOoooo-::-oooo++
10;-111222222110O--O011222222111- 01111110oOOOoo-: :-ooooo`:OO000000OO+;;+OOO000
22122222222222110++0112222222222111222222221000O+:,;.O000001111111100Oo:-OO00000
3344444433333332-,°-2333333344444433322222221100o-;oO00011222222221111O'+0111111
444444444444333320023333444444444444433322221110O.:O0011222222222222211-01112222
44444444444444443333444444444444444444333332211O. -o1112222222223333333333322222
44444444445555555555555555444444444444433333210O-"oO1122223333333444444444433333
444555555555666666666666555555555444444433333' '`:+O0233333333444444444444444433

And a link to a more readable code:

http://yannesposito.com/Scratch/en/blog/Haskell-Mandelbrot/

share|improve this answer

J, 70

3 :'try.2>|(y&+&*:)^:32[0 catch.0 end.'"0(1-~15%~i.31)j.~/2-~13%~i.40

Displays members of the set as 1, the rest as 0. Spaces each computed point two characters wide, so as to keep a mostly-square pixel with most fonts.

share|improve this answer

QBasic, 222 Characters. Not that short, but QBasic is a pretty verbose language. Also, I updated with a seemingly more correct version

FOR y=1 TO 23
FOR x=1 TO 80
a=0:b=0
c=-2.5+(x/80)*3.5:d=-1+(y/23)*2
FOR i=0 TO 1000
IF a*a+b*b>=4 THEN GOTO E
t=a*a-b*b*c:b=2*a*b+d:a=t
NEXT
E:LOCATE y,x
IF a*a+b*b<4 THEN
?("@")
ELSE
?(" ")
END IF
NEXT
NEXT

Output is as in the following image.

enter image description here

share|improve this answer

C# - 304 Chars

When I code, I code with readability and beautiful formatting. I threw up writing this.

using C=System.Console;class Program{static void Main()
{C.WindowWidth=220;C.WindowHeight=80;
int w=220,h=80,m=100;double s=4.0/w,v=4.0/h;
for(int i=0;i<h;i++)for(int j=0;j<w;j++){
double n=s*j-2,u=v*i-2,x=0,y=0;int r=0;
for(r=0;x*x+y*y<4&&r<m;r++){
double t=x*x-y*y+n;y=2*x*y+u;x=t;}
C.Write(r>=m?'#':' ');}C.ReadLine();}}

I am sure my solution can be improved but for reference I shall post it. Note that the windows console squashes the image.

enter image description here

share|improve this answer
    
It looks like a bug! –  Hosch250 Feb 13 at 2:31

C, 988 chars

Here's mine, which does an ASCII mandelbrot, written as an ASCII mandelbrot, in C.

Oh.. and it also has interactive zoom functionality. (press the keypad numbers 1-9 to zoom in on the respective area)

int main(int argc, char* argv[]){ unsigned
char c='r';double x1,y,y1,t=0,q=78,r=22,x,
x2,y2,a,b,v;do{(c=='r')?(y2=-(y1=-1.6),x1=
-2.0f,x2=0.8):(c=='?')? c=0,   printf("%f\
,%f:%f,%f",x1,y1,x2,y2):(c     <':'&&c>48)
?x=x1,y=y1,*(c>'3'&&c<':'        ?&y1: &t)
+=(y2-y1)/3,*(c>'6'&&c<            ':'?&y1
:&t)+=(y2-y1)/3, *((c               == '8'
||c+3=='8'||c+3 +3==               '8'?&x1
:&t))+=(x2-x1     )/                3,*((c
=='9'||c+3==                        '9'||c
+6=='9'                          ?&x1: &t)
)+=2*(x2-x1)                        /3,x2=
x1+(x2-x)/3,      y2                 =y1+(
y2-y)/3:(c=0);for(y=                y2;y>=
y1&&c;c=1,y-=(y2-y1)/r,            putchar
('\n')) for(x=x1;x<=x2;            x+=(x2-
x1)/q){a=b=c=0; while  (        ++c&&(a=(t
=a)*a)<4&&(v=b*b)<4)a-=v-x     ,b=y+b*2*t;
putchar("#@XMW*N&KPBQYKG$R"   "STEEVxHOUV"
"CT()[]%JL={}eou?/\\|Ili+~<>_-^\"!;:`,. "[
c?c>>2:63]);}} while((c=getchar ())!='x');
return 0;/* Mandelbrot - S.Goodwin.2001*/}

Originally posted here http://marquisdegeek.com/rnd_obs.php

share|improve this answer
    
Nice! Be sure to include a language header and byte count when answering code golf questions. Welcome to PPCG! –  Jonathan Van Matre Mar 11 at 11:11

Perl -- 193 characters

$Y=-1.2;for(0..24){$X=-2;for(0..79){($r,$i)=(0,0);for(0..15){$n=$_;$r=($x=$ r)*$x-($y=$i)*$y+$X;$i=2*$x*$y+$Y;$x*$x+$y*$y>4&&last}print unpack("\@$n a" ,".,:;=+itIYVXRBM ");$X+=3/80}$Y+=2.4/25}

Result

,,,,,,,,,,,::::::::::::;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;::::::::::::::::::::::
,,,,,,,,,:::::::::;;;;;;;;;;;;;;;;;;;;;;======+iRV+++====;;;;;;:::::::::::::::::
,,,,,,,,::::::;;;;;;;;;;;;;;;;;;;;;;========+++itVXYYRi======;;;;;;:::::::::::::
,,,,,,:::::;;;;;;;;;;;;;;;;;;;;;;=========++++ttIR  VIt+++=====;;;;;;;::::::::::
,,,,,::::;;;;;;;;;;;;;;;;;;;;==========+++iitIX        ti++++====;;;;;;;::::::::
,,,,:::;;;;;;;;;;;;;;;;;;;=========++ittttttIYX       VIItiiiii++==;;;;;;;::::::
,,,::;;;;;;;;;;;;;;;;;;======+++++iit     R               RY XX Y++=;;;;;;;;::::
,,::;;;;;;;;;;;;;;;;===+++++++++iiitIVB                        Mti++=;;;;;;;;:::
,,:;;;;;;;;;;;====+XtiiiiiiiiiittIYM                           RIti+==;;;;;;;;::
,:;;;;;=======+++iiI XVVYV VYYIIYYB                               t+===;;;;;;;;:
,;;========++++++ttIY          MRB                               Mi+===;;;;;;;;;
,========+++iiiIRYYX                                             t++====;;;;;;;;
,++iitYttttIIIVXM                                              Yti++====;;;;;;;;
,++iitYttttIIIVXM                                              Yti++====;;;;;;;;
,========+++iiiIRYYX                                             t++====;;;;;;;;
,;;========++++++ttIY          MRB                               Mi+===;;;;;;;;;
,:;;;;;=======+++iiI XVVYV VYYIIYYB                               t+===;;;;;;;;:
,,:;;;;;;;;;;;====+XtiiiiiiiiiittIYM                           RIti+==;;;;;;;;::
,,::;;;;;;;;;;;;;;;;===+++++++++iiitIVB                        Mti++=;;;;;;;;:::
,,,::;;;;;;;;;;;;;;;;;;======+++++iit     R               RY XX Y++=;;;;;;;;::::
,,,,:::;;;;;;;;;;;;;;;;;;;=========++ittttttIYX       VIItiiiii++==;;;;;;;::::::
,,,,,::::;;;;;;;;;;;;;;;;;;;;==========+++iitIX        ti++++====;;;;;;;::::::::
,,,,,,:::::;;;;;;;;;;;;;;;;;;;;;;=========++++ttIR  VIt+++=====;;;;;;;::::::::::
,,,,,,,,::::::;;;;;;;;;;;;;;;;;;;;;;========+++itVXYYRi======;;;;;;:::::::::::::
,,,,,,,,,:::::::::;;;;;;;;;;;;;;;;;;;;;;======+iRV+++====;;;;;;:::::::::::::::::

I think it won the obfuscated perl contest a few years ago.

share|improve this answer
    
So it's not yours? Might be good to say who's it from. –  Camilo Martin Jan 20 at 1:16

Python, 115.

r=range
for _ in r(-11,12):
 for f in r(-39,41):
  v=u=f/22.-_/11j;exec"u=u*u+v;"*40;print"\b"+chr(32+(u.real<4)),

Works only on 80x24 terminals, but you can add print after first for to fix it.

Sample output (With additional print instruction.):

                                       !                                        

                                   !!!                                          
                                  !!!!!                                         
                            !  ! !!!!!!!! !                                     
                           !!!!!!!!!!!!!!!!! !!                                 
                        ! !!!!!!!!!!!!!!!!!!!!!                                 
                        !!!!!!!!!!!!!!!!!!!!!!!                                 
              !  !      !!!!!!!!!!!!!!!!!!!!!!!!                                
            !!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!                                
            !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!                                 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!                                   
            !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!                                 
            !!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!                                
              !  !      !!!!!!!!!!!!!!!!!!!!!!!!                                
                        !!!!!!!!!!!!!!!!!!!!!!!                                 
                        ! !!!!!!!!!!!!!!!!!!!!!                                 
                           !!!!!!!!!!!!!!!!! !!                                 
                            !  ! !!!!!!!! !                                     
                                  !!!!!                                         
                                   !!!                                          

                                       !                                        
share|improve this answer

GolfScript - 77

20{40{0.1{.{;..*2$.*\- 20/3$-@@*10/3$-..*2$.*+1600<}*}32*\;\;@@(}60*;(n\}40*;

It can probably be golfed a lot more. The result is an approximation because I have to use integers.

Output:

000000000000000000000000000000000000000010000000000000000000
000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000001000000000000000000000000
000000000000000000000000000000000000001000000000000000000000
000000000000000000000000000000000000111000000000000000000000
000000000000000000000000000000000000111110000000000000000000
000000000000000000000000000000000000011100000000000000000000
000000000000000000000000000001000110111100010000000000000000
000000000000000000000000000000100111111111110000000000000000
000000000000000000000000000001011111111111110111000000000000
000000000000000000000000000001111111111111111110000000000000
000000000000000000000000000000111111111111111110000000000000
000000000000001000000000000011111111111111111111000000000000
000000000000000000000000000011111111111111111111000000000000
000000000000000000000000000111111111111111111111000000000000
000000000000000000000000001111111111111111111111100000000000
000000000000000001111110001111111111111111111111100000000000
000000000000000011111111101111111111111111111111100000000000
000000000000100111111111111111111111111111111111000000000000
000000000001101111111111111111111111111111111111000000000000
011111111111111111111111111111111111111111111100000000000000
000000000000001111111111111111111111111111111110000000000000
000000000000000111111111111111111111111111111111000000000000
000000000000000001111111111111111111111111111111100000000000
000000000000000001111111101111111111111111111111000000000000
000000000000000001011100000111111111111111111111100000000000
000000000000000000000100000111111111111111111111000000000000
000000000000000100000000001111111111111111111111100000000000
000000000000000100000000000011111111111111111111000000000000
000000000000000000000000000011111111111111111110000000000000
000000000000000000000000000001111111111111111111000000000000
000000000000000000000000000000111111111111111111000000000000
000000000000000000000000000001101111111111111000000000000000
000000000000000000000000000011000011111110100000000000000000
000000000000000000000000000000000000111100000000000000000000
000000000000000000000000000000000000111110000000000000000000
000000000000000000000000000000000000111100000000000000000000
000000000000000000000000000000000000011000000000000000000000
000000000000000000000000000000000000001000000000000000000000
000000000000000000000000000000000000000000000000000000000000

It takes about 9 more bytes to make it use spaces and stars:

20{40{0.1{.{;..*2$.*\- 20/3$-@@*10/3$-..*2$.*+1600<}*}32*' *'=\;\;@@(}60*;(n\}40*;]''+
share|improve this answer

GNU bc, 136 bytes

for(y=-1;y<1;y+=.05){for(x=-2;x<1;x+=.05){for(n=i=r=0;r*r+i*i<4&&++n<32;r=t){t=r*r-i*i+x
i=2*r*i+y}
if(n<32)print n%A else print " "}
2}

Output:

1111112222233333333333333334444445567190 54444333322222222222
11111222233333333333333334444444555780 0765444433333222222222
11111222333333333333333344444445556799 1865544443333322222222
11112223333333333333333444444455561 6  7985554444333332222222
111122333333333333333344444445566784    086555544333333222222
111222333333333333333444444556667797    787665554433333222222
111223333333333333344444455678988903    309866625443333322222
11123333333333333344444555673430   0    203 98897543333332222
11223333333333333444455556672  75          224654544333332222
11233333333333344455555566781                  29554333333222
11233333333333445555555666808                   7654333333222
113333333334445666555666782 5                  37654433333322
123333334444557477778777782                    70254433333322
12333344444556749990198881                        64433333322
13334444445556709 25 51902                      4864433333332
13344444455557795      728                      4054443333332
1344444455557792        6                        854443333332
1444444555672919                                 654443333332
144444666678368                                 8654443333332
1556787778915                                  07654443333332
1                                             387654443333332
1556787778915                                  07654443333332
144444666678368                                 8654443333332
1444444555672919                                 654443333332
1344444455557792        6                        854443333332
13344444455557795      728                      4054443333332
13334444445556709 25 51902                      4864433333332
12333344444556749990198881                        64433333322
123333334444557477778777782                    70254433333322
113333333334445666555666782 5                  37654433333322
11233333333333445555555666808                   7654333333222
11233333333333344455555566781                  29554333333222
11223333333333333444455556672  75          224654544333332222
11123333333333333344444555673430   0    203 98897543333332222
111223333333333333344444455678988903    309866625443333322222
111222333333333333333444444556667797    787665554433333222222
111122333333333333333344444445566784    086555544333333222222
11112223333333333333333444444455561 6  7985554444333332222222
11111222333333333333333344444445556799 1865544443333322222222
11111222233333333333333334444444555780 0765444433333222222222
share|improve this answer

Python 444

print (lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+y,map(lambda y,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,Sy=Sy,L=lambda yc,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,i=IM,Sx=Sx,Sy=Sy:reduce(lambda x,y:x+y,map(lambda x,xc=Ru,yc=yc,Ru=Ru,Ro=Ro,i=i,Sx=Sx,F=lambda xc,yc,x,y,k,f=lambda xc,yc,x,y,k,f:(k<=0)or (x*x+y*y>=4.0) or 1+f(xc,yc,x*x-y*y+xc,2.0*x*y+yc,k-1,f):f(xc,yc,x,y,k,f):chr(64+F(Ru+x*(Ro-Ru)/Sx,yc,0,0,i)),range(Sx))):L(Iu+y*(Io-Iu)/Sy),range(Sy))))(-2.1, 0.7, -1.2, 1.2, 30, 80, 24)

Here's one from the python developers,
which though isn't really short,
is one line which is pretty boss.

share|improve this answer

c++-11 -- 298 characters

Fully golfed, unparameterized version that does only what is required:

#include <complex>
#include <iostream>
#define C complex<float>
using namespace std;int main(void){C p(-2,1),q(1,-1);char i,j,k;
for(j=0;j<30;++j){for(i=0;i<80;++i){C r=q-p,c((i+0.5)*r.real()/
81+p.real(),(j+0.5)*r.imag()/31+p.imag());r=0;k=64;while
(abs(r)<=2&&(--k!=32))r=r*r+c;cout<<k;}cout<<endl;}}

The implementation is completely unremarkable. Just seeing what can be done using the native complex time (which is, alas, a little wordy).

Ungolfed and parameterized so that it can do regions

#include <complex>
#include <iostream>
using namespace std;
void M/*andlebrot*/(ostream& o, 
            complex<float> p, complex<float> q, 
            int l, int h) {
  char i,j,k;
  for(j=0; j<h; ++j){
    for(i=0; i<l; ++i){
      complex<float> r=q-p,c((i+0.5)*r.real()/(l+1)+p.real(), 
                 (j+0.5)*r.imag()/(h+1)+p.imag() );
      r=0;
      k='@';
      while(abs(r)<=2&&(--k!=' ')){
        r=r*r+c;
      }
      o<<k;
    }
    o<<endl;
  }
}

int main(int argc, char*argv[]){
  M(cout,complex<float>(-2.15,1.25),complex<float>(0.65,-1.25),80,30);
}

Output

$ g++-fsf-4.7  mandelbrot_golf.cc --std=c++11
$ ./a.out
???????>>>>>>=====================<<<<<<<<<;;;;:974048:;<<<<<<======>>>>>>>>>>>>
??????>>>>>=====================<<<<<<<<<<;;;:9872  '89:;;<<<<<<======>>>>>>>>>>
?????>>>>=====================<<<<<<<<<<;;;::8$ /#  &349:;;;;<<<<=======>>>>>>>>
????>>>=====================<<<<<<<<<;;::::9986-     *589::;;;;<<<========>>>>>>
????>>====================<<<<<<<<;;;9988998775/      57889::::9;<<========>>>>>
???>>===================<<<<<<;;;;;:96$.355 &()         2$28887,8:;<========>>>>
??>>==================<<<<;;;;;;;::987.                    2$   )9;<<========>>>
??>================<<<;;;;;;;;;::::8753+                       '8:;;<<========>>
?>=============<<<;::::;;;;;::::997                            589:;<<=========>
?>========<<<<<;;;:85899987999998861%                           (54;<<<========>
?=====<<<<<<<;;;;::8 03564&46677763!                             28:<<<=========
>==<<<<<<<<;;;;;::9873  ,   '  554#                              69;<<<<========
==<<<<<<<<;;;;;:998$3,          00                              -3:;<<<<========
=<<<<<<<;;::::975654)            )                              ,9:;<<<<========
<;;;::99:::999762  #                                            9:;;<<<<========
                                                             /589:;;<<<<========
<;;;::99:::999762  #                                            9:;;<<<<========
=<<<<<<<;;::::975654)            )                              ,9:;<<<<========
==<<<<<<<<;;;;;:998$3,          00                              -3:;<<<<========
>==<<<<<<<<;;;;;::9873  ,   '  554#                              69;<<<<========
?=====<<<<<<<;;;;::8 03564&46677763!                             28:<<<=========
?>========<<<<<;;;:85899987999998861%                           (54;<<<========>
?>=============<<<;::::;;;;;::::997                            589:;<<=========>
??>================<<<;;;;;;;;;::::8753+                       '8:;;<<========>>
??>>==================<<<<;;;;;;;::987.                    2$   )9;<<========>>>
???>>===================<<<<<<;;;;;:96$.355 &()         2$28887,8:;<========>>>>
????>>====================<<<<<<<<;;;9988998775/      57889::::9;<<========>>>>>
????>>>=====================<<<<<<<<<;;::::9986-     *589::;;;;<<<========>>>>>>
?????>>>>=====================<<<<<<<<<<;;;::8$ /#  &349:;;;;<<<<=======>>>>>>>>
??????>>>>>=====================<<<<<<<<<<;;;:9872  '89:;;<<<<<<======>>>>>>>>>>
share|improve this answer
    
The parens in the middle add a nice touch :) –  Camilo Martin Jan 20 at 1:17
    
I wish I could claim I planned it, but it just happened. I set the character selection to allow the largest range of printables. –  dmckee Jan 20 at 1:24

Python 3

Translation from perl (193) with some improvements

185 chars

Y=-1.2
r=range
for _ in r(25):
 X=-2
 for _ in r(80):
  r=i=0
  for n in r(16):
   r,i=r*r-i*i+X,2*r*i+Y
   if r*r+i*i>4:break
  print(".,:;=+itIYVXRBM "[n],end='')
  X+=3/80
 Y+=2.4/25
share|improve this answer

c++ (260)

Golfed Code:

#include<iostream>
void main(){for(float i=-1;i<=1;i+=0.03125){for(float r=-2;r<=1;r+=.03125){float zr=r,zi=i;for(int n=0;n<31;n++){float nzr=zr*zr-zi*zi;zi=zr*zi*2;zr=nzr;zr+=r;zi+=i;}if(zi*zi+zr*zr<4){std::cout<<"*";}else{std::cout<<" ";}}std::cout<<"\n";}}

Example output:

                                                               *



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



                                                               *
share|improve this answer
    
you included math for sqrt(x^2+y^2) < 2. You can compare with 4 and remove the sqrt and the include. –  ilmale Apr 22 at 0:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.