text:
Draw A Sierpinski Triangle
The Sierpinsky Triangle is a fractal created by taking a triangle, decreasing the height and width by 1/2, creating 3 copies of the resulting triangle, and place them such each triangle touches the other two on a corner.  This process is repeated over and over again with the resulting triangles to produce the Sierpinski triangle, as illustrated below.

Write a program to generate a Sierpinski triangle.  You can use any method you want to generate the pattern, either by drawing the actual triangles, or by using a random algorithm to generate the picture.  You can draw in pixels, ascii art, or whatever you want, so long as the output looks similar to the last picture shown above.  Fewest characters wins.

See also the old Stack Overflow version: http://stackoverflow.com/questions/1726698/code-golf-sierpinskis-triangle

I got the idea for this after seeing the pascal's triangle question, and remembering the example program for this in my TI-86 manual.  I decided to convert it to QBasic and then code golf it.

There is no problem with running a challenge here that was already run on Stack Overflow, but many people will not want to present the same material again. So I link them for the edification of later visitors.

To avoid duplication, perhaps you should change to rules to allow only graphical implementations.

Lots of ideas from wolfram: http://www.wolframscience.com/nksonline/page-931

A lot of rulesets in one-dimensional cellular automatas produce this triangle, maybe that could be used. I have a separate question on that

HTML + JavaScript, 150 characters (see notes for 126 characters)
Whitespace inserted for readability and not counted.
<title></title><canvas></canvas><script>
for(x=k=128;x--;)for(y=k;y--;)
  x&y||document.body.firstChild.getContext("2d").fillRect(x-~y/2,k-y,1,1)
</script>

The core of it is applying the rule of coloring pixels for which x & y == 0 by the conditional x&y||, which produces a “Sierpinski right triangle”; and x-~y/2,k-y are a coordinate transformation to produce the approximately equilateral display.

A less correct (HTML-wise) version is 126 characters:
<canvas><script>
for(x=k=128;x--;)for(y=k;y--;)
  x&y||document.body.firstChild.getContext("2d").fillRect(x-~y/2,k-y,1,1)
</script>

(The way in which this is less correct is that it omits the title element and the end tag of the canvas element, both of which are required for a correct document even though omitting them does not change the interpretation of the document.)
Three characters can be saved by eliminating k in favor of the constant 64, at the cost of a smaller result; I wouldn't count the 8 option as it has insufficient detail.
Note that a size of 256 or higher requires attributes on the <canvas> to increase the canvas size from the default.

Nobody cares if your HTML validates at codegolf :-) Some improvements: <canvas id=c> and then c.getContext. Shorten loops: for(x=k=128;x--;)for(y=k;y--;)

ids being turned into global variables is a horrible misfeature which I refuse to acknowledge, and WebKit does not implement it in standards mode. Thank you for the loop trick.

Minor improvement: x&y?0: can be replaced with x&y|| Otherwise nice solution.

Bravo, this is just wonderful.

As this contains a script, I'd recommend titling it as HTML + Javascript. That'll make it clearer to someone skimming what sort of answer it is.

GolfScript (43 42 chars)
' /\ /__\ '4/){.+\.{[2$.]*}%\{.+}%+\}3*;n*

Output:
               /\
              /__\
             /\  /\
            /__\/__\
           /\      /\
          /__\    /__\
         /\  /\  /\  /\
        /__\/__\/__\/__\
       /\              /\
      /__\            /__\
     /\  /\          /\  /\
    /__\/__\        /__\/__\
   /\      /\      /\      /\
  /__\    /__\    /__\    /__\
 /\  /\  /\  /\  /\  /\  /\  /\
/__\/__\/__\/__\/__\/__\/__\/__\

Change the "3" to a larger number for a larger triangle.

Python (234)
Maximal golfing, tiny image:
#!/usr/bin/env python3
from cairo import*
s=SVGSurface('_',97,84)
g=Context(s)
g.scale(97,84)
def f(w,x,y):
 v=w/2
 if w>.1:f(v,x,y);f(v,x+w/4,y-v);f(v,x+v,y)
 else:g.move_to(x,y);g.line_to(x+v,y-w);g.line_to(x+w,y);g.fill()
f(1,0,1)
s.write_to_png('s.png')

Requires python3-cairo.
To get a nice large image I needed 239 characters.

import cairo as c whould save you a few characters

this answer needs more upvotes

Mathematica - 32 characters
Nest[Subsuperscript[#,#,#]&,0,5]

Mathematica - 37 characters
Grid@CellularAutomaton[90,{{1},0},31]

This will produce a 2D table of 0 and 1, where 1s are drawing Sierpinski Triangle.

At the cost of 5 additional characters, your second solution will display better with ArrayPlot@CellularAutomaton[90, {{1}, 0}, 31] or MatrixPlot@CellularAutomaton[90, {{1}, 0}, 31].

...or with ReliefPlot@...

I get this.  How did you get the output without all the brackets?

@Mr.Wizard hmm... where in the world brackets are from? It even works here: http://www.mathics.net Try and let me know.

@Mr.Wizard Also take a look at this: http://wolfram.com/xid/0dek1w-y16

+1 Vitaliy: my golfed L-fractal generator in Mma: http://codegolf.stackexchange.com/a/9351/315

@Vitaliy Kaurov The primary (32 character) solution is astonishing. Can you do the "fractal tree" challenge (elsewhere on PCG) using the same technique?

@MichaelStern Thanks! I did the tree HERE but with other idea. I think it is possible to do the tree with nesting -scripts[] - perhaps even randomly selecting ones from a set to give it a random natural look. I have to find some time for it ;)

Since v. 11.1 there is a built-in: SierpinskiMesh[n]

Python, 101 86
Uses the rule 90 automaton.
x=' '*31
x+='.'+x
exec"print x;x=''.join(' .'[x[i-1]!=x[i-62]]for i in range(63));"*32

This is longer, but prettier.
x=' '*31
x+=u'Δ'+x
exec u"print x;x=''.join(u' Δ'[x[i-1]!=x[i-62]]for i in range(63));"*32

Edit: playing with strings directly, got rid of obnoxiously long slicing, made output prettier.
Output:
                               Δ
                              Δ Δ
                             Δ   Δ
                            Δ Δ Δ Δ
                           Δ       Δ
                          Δ Δ     Δ Δ
                         Δ   Δ   Δ   Δ
                        Δ Δ Δ Δ Δ Δ Δ Δ
                       Δ               Δ
                      Δ Δ             Δ Δ
                     Δ   Δ           Δ   Δ
                    Δ Δ Δ Δ         Δ Δ Δ Δ
                   Δ       Δ       Δ       Δ
                  Δ Δ     Δ Δ     Δ Δ     Δ Δ
                 Δ   Δ   Δ   Δ   Δ   Δ   Δ   Δ
                Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ
               Δ                               Δ
              Δ Δ                             Δ Δ
             Δ   Δ                           Δ   Δ
            Δ Δ Δ Δ                         Δ Δ Δ Δ
           Δ       Δ                       Δ       Δ
          Δ Δ     Δ Δ                     Δ Δ     Δ Δ
         Δ   Δ   Δ   Δ                   Δ   Δ   Δ   Δ
        Δ Δ Δ Δ Δ Δ Δ Δ                 Δ Δ Δ Δ Δ Δ Δ Δ
       Δ               Δ               Δ               Δ
      Δ Δ             Δ Δ             Δ Δ             Δ Δ
     Δ   Δ           Δ   Δ           Δ   Δ           Δ   Δ
    Δ Δ Δ Δ         Δ Δ Δ Δ         Δ Δ Δ Δ         Δ Δ Δ Δ
   Δ       Δ       Δ       Δ       Δ       Δ       Δ       Δ
  Δ Δ     Δ Δ     Δ Δ     Δ Δ     Δ Δ     Δ Δ     Δ Δ     Δ Δ
 Δ   Δ   Δ   Δ   Δ   Δ   Δ   Δ   Δ   Δ   Δ   Δ   Δ   Δ   Δ   Δ
Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ

That looks really cool :D

Using that U+0394 capital Delta is a really nice touch.

J
,/.(,~,.~)^:6,'o'

Not ideal, since the triangle is lopsided and followed by a lot of whitespace - but interesting nonetheless I thought.
Output:
o
oo
o o
oooo
o   o
oo  oo
o o o o
oooooooo
o       o
oo      oo
o o     o o
oooo    oooo
o   o   o   o
oo  oo  oo  oo
o o o o o o o o
oooooooooooooooo
o               o
oo              oo
o o             o o
oooo            oooo
o   o           o   o
oo  oo          oo  oo
o o o o         o o o o
oooooooo        oooooooo
o       o       o       o
oo      oo      oo      oo
o o     o o     o o     o o
oooo    oooo    oooo    oooo
o   o   o   o   o   o   o   o
oo  oo  oo  oo  oo  oo  oo  oo
o o o o o o o o o o o o o o o o
oooooooooooooooooooooooooooooooo
o                               o
oo                              oo
o o                             o o
oooo                            oooo
o   o                           o   o
oo  oo                          oo  oo
o o o o                         o o o o
oooooooo                        oooooooo
o       o                       o       o
oo      oo                      oo      oo
o o     o o                     o o     o o
oooo    oooo                    oooo    oooo
o   o   o   o                   o   o   o   o
oo  oo  oo  oo                  oo  oo  oo  oo
o o o o o o o o                 o o o o o o o o
oooooooooooooooo                oooooooooooooooo
o               o               o               o
oo              oo              oo              oo
o o             o o             o o             o o
oooo            oooo            oooo            oooo
o   o           o   o           o   o           o   o
oo  oo          oo  oo          oo  oo          oo  oo
o o o o         o o o o         o o o o         o o o o
oooooooo        oooooooo        oooooooo        oooooooo
o       o       o       o       o       o       o       o
oo      oo      oo      oo      oo      oo      oo      oo
o o     o o     o o     o o     o o     o o     o o     o o
oooo    oooo    oooo    oooo    oooo    oooo    oooo    oooo
o   o   o   o   o   o   o   o   o   o   o   o   o   o   o   o
oo  oo  oo  oo  oo  oo  oo  oo  oo  oo  oo  oo  oo  oo  oo  oo
o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o
oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

A quick explanation:
The verb (,~,.~) is what's doing the work here. It's a hook which first stitches ,. the argument to itself (o -> oo) and then appends the original argument to the output:
oo

becomes
oo
o

This verb is repeated 6 times ^:6 with the output of each iteration becoming the input of the next iteration. So
oo
o

becomes
oooo
o o
oo
o

which in turn becomes
oooooooo
o o o o
oo  oo
o   o
oooo
o o
oo
o

etc. I've then used the oblique adverb on append ,/. to read the rows diagonally to straighten(ish) the triangle. I didn't need to do this, as randomra points out. I could have just reversed |. the lot to get the same result. Even better, I could have just used (,,.~)^:6,'o' to save the reverse step completely.
Ah well, you live and learn. :-)

Could you briefly explain how it works? I'm not familiar with J

|.(,~,.~)^:6,'o' is shorter and without extra spaces. And (,~,.~)^:6,1 also gives decent input in just 12 characters!

@aditsu I've added an explanation.

So if I get it, that operator concatenates two 2d arrays?

8086 Machine code - 30 bytes.
NOTE: This is not my code and should not be accepted as an answer. I found this while working on a different CG problem to emulate an 8086 CPU. The included text file credits David Stafford, but that's the best I could come up with.
I'm posting this because it's clever, short, and I thought you'd want to see it.
It makes use of overlapping opcodes to pack more instructions in a smaller space. Amazingly clever. Here is the machine code:
B0 13 CD 10 B3 03 BE A0 A0 8E DE B9 8B 0C 32 28 88 AC C2 FE 4E 75 F5 CD 16 87 C3 CD 10 C3

A straight-up decode looks like this:
0100: B0 13              mov AL, 13h
0102: CD 10              int 10h
0104: B3 03              mov BL, 3h
0106: BE A0 A0           mov SI, A0A0h
0109: 8E DE              mov  DS, SI
010B: B9 8B 0C           mov CX, C8Bh
010E: 32 28              xor  CH, [BX+SI]
0110: 88 AC C2 FE        mov  [SI+FEC2h], CH
0114: 4E                 dec SI
0115: 75 F5              jne/jnz -11

When run, when the jump at 0x0115 happens, notice it jumps back to 0x010C, right into the middle of a previous instruction:
0100: B0 13              mov AL, 13h
0102: CD 10              int 10h
0104: B3 03              mov BL, 3h
0106: BE A0 A0           mov SI, A0A0h
0109: 8E DE              mov  DS, SI
010B: B9 8B 0C           mov CX, C8Bh
010E: 32 28              xor  CH, [BX+SI]
0110: 88 AC C2 FE        mov  [SI+FEC2h], CH
0114: 4E                 dec SI
0115: 75 F5              jne/jnz -11
010C: 8B 0C              mov  CX, [SI]
010E: 32 28              xor  CH, [BX+SI]
0110: 88 AC C2 FE        mov  [SI+FEC2h], CH
0114: 4E                 dec SI
0115: 75 F5              jne/jnz -11
010C: 8B 0C              mov  CX, [SI]

Brilliant! Hope you guys don't mind me sharing this. I know it's not an answer per se, but it's of interest to the challenge.
Here it is in action:

Python (42)
I originally wanted to post a few suggestions on boothbys solution (who actually uses rule 18 :), but i didn't have enough reputation to comment, so i made it into another answer. Since he changed his approach, i added some explanation.
My suggestions would have been:

use '%d'*64%tuple(x) instead of ''.join(map(str,x)
shift in zeros instead of wraping the list around

which would have led to the following code (93 characters):
x=[0]*63
x[31]=1
exec"print'%d'*63%tuple(x);x=[a^b for a,b in zip(x[1:]+[0],[0]+x[:-1])];"*32

But i optimzed further, first by using a longint instead of an integer array and just printing the binary representation (75 characters):
x=2**31
exec"print'%d'*63%tuple(1&x>>i for i in range(63));x=x<<1^x>>1;"*32

And finally by printing the octal representation, which is already supported by printf interpolation (42 characters):
x=8**31
exec"print'%063o'%x;x=x*8^x/8;"*32

All of them will print:
000000000000000000000000000000010000000000000000000000000000000
000000000000000000000000000000101000000000000000000000000000000
000000000000000000000000000001000100000000000000000000000000000
000000000000000000000000000010101010000000000000000000000000000
000000000000000000000000000100000001000000000000000000000000000
000000000000000000000000001010000010100000000000000000000000000
000000000000000000000000010001000100010000000000000000000000000
000000000000000000000000101010101010101000000000000000000000000
000000000000000000000001000000000000000100000000000000000000000
000000000000000000000010100000000000001010000000000000000000000
000000000000000000000100010000000000010001000000000000000000000
000000000000000000001010101000000000101010100000000000000000000
000000000000000000010000000100000001000000010000000000000000000
000000000000000000101000001010000010100000101000000000000000000
000000000000000001000100010001000100010001000100000000000000000
000000000000000010101010101010101010101010101010000000000000000
000000000000000100000000000000000000000000000001000000000000000
000000000000001010000000000000000000000000000010100000000000000
000000000000010001000000000000000000000000000100010000000000000
000000000000101010100000000000000000000000001010101000000000000
000000000001000000010000000000000000000000010000000100000000000
000000000010100000101000000000000000000000101000001010000000000
000000000100010001000100000000000000000001000100010001000000000
000000001010101010101010000000000000000010101010101010100000000
000000010000000000000001000000000000000100000000000000010000000
000000101000000000000010100000000000001010000000000000101000000
000001000100000000000100010000000000010001000000000001000100000
000010101010000000001010101000000000101010100000000010101010000
000100000001000000010000000100000001000000010000000100000001000
001010000010100000101000001010000010100000101000001010000010100
010001000100010001000100010001000100010001000100010001000100010
101010101010101010101010101010101010101010101010101010101010101

Of course there is also a graphical solution (131 characters):
from PIL.Image import*
from struct import*
a=''
x=2**31
exec"a+=pack('>Q',x);x=x*2^x/2;"*32
fromstring('1',(64,32),a).save('s.png')

:D

36: x=8**31;exec"print'%o'%x;x^=x/8;"*32

QBasic 151 Characters
As an example, here is how it can be done in QBasic.
SCREEN 9
H=.5
P=300
FOR I=1 TO 9^6
    N=RND
    IF N > 2/3 THEN
        X=H+X*H:Y=Y*H
    ELSEIF N > 1/3 THEN
        X=H^2+X*H:Y=H+Y*H
    ELSE
        X=X*H:Y=Y*H
    END IF
    PSET(P-X*P,P-Y*P)
NEXT

Could you describe the measure under which this program is 129 characters? I get 151 if I strip out all the probably-unnecessary whitespace. (I'm not familiar with QBasic.)

I stripped out all the whitespace for my count.  I guess I could count only non-essential whitespace. I'm not sure what the "official" rule is for code golf.

You should count the actual number of characters, including whitespace, in a program which runs and produces the correct output. Naturally you'll want to have no unnecessary whitespace.

Corrected my character count.

Haskell (291)
I'm not very good at golfing haskell codes.
solve n = tri (putStrLn "") [2^n] n
tri m xs 1 =
  do putStrLn (l1 1 xs "/\\" 0)
     putStrLn (l1 1 xs "/__\\" 1)
     m
tri m xs n=tri m' xs (n-1)
  where m'=tri m (concat[[x-o,x+o]|x<-xs]) (n-1)
        o=2^(n-1)
l1 o [] s t=""
l1 o (x:xs) s t=replicate (x-o-t) ' '++s++l1 (x+2+t) xs s t

Output of solve 4 is:
               /\
              /__\
             /\  /\
            /__\/__\
           /\      /\
          /__\    /__\
         /\  /\  /\  /\
        /__\/__\/__\/__\
       /\              /\
      /__\            /__\
     /\  /\          /\  /\
    /__\/__\        /__\/__\
   /\      /\      /\      /\
  /__\    /__\    /__\    /__\
 /\  /\  /\  /\  /\  /\  /\  /\
/__\/__\/__\/__\/__\/__\/__\/__\

APL (51)
      A←67⍴0⋄A[34]←1⋄' ○'[1+32 67⍴{~⊃⍵:⍵,∇(1⌽⍵)≠¯1⌽⍵⋄⍬}A]

Explanation:

A←67⍴0: A is a vector of 67 zeroes
A[34]←1: the 34th element is 1
{...}A: starting with A, do:
~⊃⍵:: if the first element of the current row is zero
⍵,∇: add the current row to the answer, and recurse with:
(1⌽⍵)≠¯1⌽⍵: the vector where each element is the XOR of its neighbours in the previous generation
⋄⍬: otherwise, we're done
32 67⍴: format this in a 67x32 matrix
1+: add one to select the right value from the character array
' ○'[...]: output either a space (not part of the triangle) or a circle (when it is part of the triangle)

Output:

                                 ○
                                ○ ○
                               ○   ○
                              ○ ○ ○ ○
                             ○       ○
                            ○ ○     ○ ○
                           ○   ○   ○   ○
                          ○ ○ ○ ○ ○ ○ ○ ○
                         ○               ○
                        ○ ○             ○ ○
                       ○   ○           ○   ○
                      ○ ○ ○ ○         ○ ○ ○ ○
                     ○       ○       ○       ○
                    ○ ○     ○ ○     ○ ○     ○ ○
                   ○   ○   ○   ○   ○   ○   ○   ○
                  ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
                 ○                               ○
                ○ ○                             ○ ○
               ○   ○                           ○   ○
              ○ ○ ○ ○                         ○ ○ ○ ○
             ○       ○                       ○       ○
            ○ ○     ○ ○                     ○ ○     ○ ○
           ○   ○   ○   ○                   ○   ○   ○   ○
          ○ ○ ○ ○ ○ ○ ○ ○                 ○ ○ ○ ○ ○ ○ ○ ○
         ○               ○               ○               ○
        ○ ○             ○ ○             ○ ○             ○ ○
       ○   ○           ○   ○           ○   ○           ○   ○
      ○ ○ ○ ○         ○ ○ ○ ○         ○ ○ ○ ○         ○ ○ ○ ○
     ○       ○       ○       ○       ○       ○       ○       ○
    ○ ○     ○ ○     ○ ○     ○ ○     ○ ○     ○ ○     ○ ○     ○ ○
   ○   ○   ○   ○   ○   ○   ○   ○   ○   ○   ○   ○   ○   ○   ○   ○
  ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○

Yikes.  I expected this to be 4 characters, using binomials mod 2... (ok... maybe a little longer than that)

80x86 Code / MsDos - 10 Bytes
As a sizecoder specialized for very tiny intros on MsDos i managed to come up with a program that occupies only 10 bytes.
in hex:
04 13 CD 10 20 E9 B4 0C E2 F6

in asm:
X: add al,0x13
int 0x10
and cl,ch
mov ah,0x0C
loop X

The first version i coded was "Colpinski" which is 16 bytes in size, and even interactive in a way that you can change the color with the keyboard and the mouse. Together with "Frag" - another sizecoder - we brought that one down to 13 bytes, allowing for a 10 byte program which just contains the core routine.
It gets a bit more interesting when things are animated, so i'll mention another  version, Zoompinski 64 - trying to mimic the exact behavior of "Zoompinski C64" in 512 bytes - also for MsDos, 64 bytes in size as the name suggests.
It's possible to optimize this further downto 31 Bytes, while losing elegance, colors and symmetry (source and executable available behind the link above)
Download the original and comment on "Pouet"

You should post a hex dump of your code, so we can see the actual bytes.

C 127 119 116 108 65
This one uses the trick of the HTML answer of ^ i & j getting it to print pretty output would take 1 more char (you can get really ugly output by sacrificing the a^).
a=32,j;main(i){for(;++i<a;)putchar(a^i&j);++j<a&&main(puts(""));}

To make it pretty turn (32^i&j) to (32|!(i&j)) and turn it from ++i<a to ++i<=a. However wasting chars on looks seems ungolfish to me.
Ugly output:
 ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
""  ""  ""  ""  ""  ""  ""  ""
"# !"# !"# !"# !"# !"# !"# !"#
  $$$$    $$$$    $$$$    $$$$
 !$%$% ! !$%$% ! !$%$% ! !$%$%
""$$&&  ""$$&&  ""$$&&  ""$$&&
"#$%&' !"#$%&' !"#$%&' !"#$%&'
      ((((((((        ((((((((
 ! ! !()()()() ! ! ! !()()()()
""  ""((**((**  ""  ""((**((**
"# !"#()*+()*+ !"# !"#()*+()*+
  $$$$((((,,,,    $$$$((((,,,,
 !$%$%()(),-,- ! !$%$%()(),-,-
""$$&&((**,,..  ""$$&&((**,,..
"#$%&'()*+,-./ !"#$%&'()*+,-./
              0000000000000000
 ! ! ! ! ! ! !0101010101010101
""  ""  ""  ""0022002200220022
"# !"# !"# !"#0123012301230123
  $$$$    $$$$0000444400004444
 !$%$% ! !$%$%0101454501014545
""$$&&  ""$$&&0022446600224466
"#$%&' !"#$%&'0123456701234567
      ((((((((0000000088888888
 ! ! !()()()()0101010189898989
""  ""((**((**0022002288::88::
"# !"#()*+()*+0123012389:;89:;
  $$$$((((,,,,000044448888<<<<
 !$%$%()(),-,-010145458989<=<=
""$$&&((**,,..0022446688::<<>>
"#$%&'()*+,-./0123456789:;<=>?

I actually kind of like how it looks. But if you insist on it being pretty you can dock four chars. Pretty Output:
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
  !!  !!  !!  !!  !!  !!  !!  !
  !   !   !   !   !   !   !   !
!!    !!!!    !!!!    !!!!    !
!     ! !     ! !     ! !     !
      !!      !!      !!      !
      !       !       !       !
!!!!!!        !!!!!!!!        !
! ! !         ! ! ! !         !
  !!          !!  !!          !
  !           !   !           !
!!            !!!!            !
!             ! !             !
              !!              !
              !               !
!!!!!!!!!!!!!!                !
! ! ! ! ! ! !                 !
  !!  !!  !!                  !
  !   !   !                   !
!!    !!!!                    !
!     ! !                     !
      !!                      !
      !                       !
!!!!!!                        !
! ! !                         !
  !!                          !
  !                           !
!!                            !
!                             !
                              !
                              !

Leaving up the older 108 char, cellular automata version.
j,d[99][99];main(i){d[0][31]=3;for(;i<64;)d[j+1][i]=putchar(32|d[j][i+2]^d[j][i++]);++j<32&&main(puts(""));}

So I don't think I'm going to get it much shorter than this so I'll explain the code. I'll leave this explanation up, as some of the tricks could be useful.
j,d[99][99]; // these init as 0
main(i){ //starts at 1 (argc)
  d[0][48]=3; //seed the automata (3 gives us # instead of !)
  for(;i<98;) // print a row
    d[j+1][i]=putchar(32|d[j][i+2]]^d[j][i++]);
    //relies on undefined behavoir. Works on ubuntu with gcc ix864
    //does the automata rule. 32 + (bitwise or can serve as + if you know
    //that (a|b)==(a^b)), putchar returns the char it prints
  ++j<32&&main(puts(""));
  // repeat 32 times
  // puts("") prints a newline and returns 1, which is nice
}

Some output
                             # #
                            #   #
                           # # # #
                          #       #
                         # #     # #
                        #   #   #   #
                       # # # # # # # #
                      #               #
                     # #             # #
                    #   #           #   #
                   # # # #         # # # #
                  #       #       #       #
                 # #     # #     # #     # #
                #   #   #   #   #   #   #   #
               # # # # # # # # # # # # # # # #
              #                               #
             # #                             # #
            #   #                           #   #
           # # # #                         # # # #
          #       #                       #       #
         # #     # #                     # #     # #
        #   #   #   #                   #   #   #   #
       # # # # # # # #                 # # # # # # # #
      #               #               #               #
     # #             # #             # #             # #
    #   #           #   #           #   #           #   #
   # # # #         # # # #         # # # #         # # # #
  #       #       #       #       #       #       #       #
 # #     # #     # #     # #     # #     # #     # #     # #
#   #   #   #   #   #   #   #   #   #   #   #   #   #   #   #
 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

This does not appear to be a Sierpinski triangle; it splits into three sub-triangles (proceeding downward) rather than two, and it can be seen that this produces no large central empty triangle.

That's because I used the wrong rule :O. Fixed, and shaved a couple of chars.

Suggest for(31[*d]=3; instead of d[0][31]=3;for(;

PostScript, 120 chars
-7 -4 moveto
14 0 rlineto
7{true upath dup
2{120 rotate uappend}repeat[2 0 0 2 7 4]concat}repeat
matrix setmatrix
stroke

Ghostscript output:

This is drawing the figure by recursively tripling what's already drawn.
First step is drawing a line. The line is saved as a userpath, then the userpath is added two more times after rotating 120 degrees each time. [2 0 0 2 7 4]concat moves the "rotation point" to the center of the next big white "center triangle" that is to be enclosed by replications of the triangle we already have. Here, we're back to step 1 (creating a upath that's tripled by rotation).
The number of iterations is controlled by the first number in line 3.

+1 Very nice. I had no idea upath could be used like that.

Hey, you've got the rep to add that image now!

@luserdroog: That's right (even partly thanks to you)!

J (9 characters)
Easily the ugliest, you really need to squint to see the output ;)
2|!/~i.32

produces the output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1
0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1
0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1
0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1
0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1
0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1
0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
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 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1
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 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 1 1 1 1 1 1 1 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 1 0 1 0 1 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 1 1 0 0 1 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 1 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 1 1 1 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 1 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 1 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 1

of course you can display it graphically:
load 'viewmat'
viewmat 2|!/~i.32

how the...  what?

The code exploits the property of Pascal's triangle that if you colour all the odd (even) numbers black (white), you end up with the Sierpinski triangle. (see this image).
i.32 generates the list 0 1 2 ... 31. Then !/~ computes the binomial coefficients of each element in the list against itself, i.e. produces a 32 x 32 matrix which has Pascal's triangle embedded in it. Then 2| is simply each element in this matrix mod 2, producing Sierpinski's triangle.

Python (75)
I'm two years late to the party, but I'm surprised that nobody has taken this approach yet
from pylab import*
x=[[1,1],[1,0]]
for i in'123':x=kron(x,x)
imsave('a',x)

Uses the Kronecker product to replace a matrix by multiple copies of itself.
I could save two chars by using x=kron(x,x);x=kron(x,x) in line three to get a 16x16 pixel image with three visible levels or add another char to the iterator  and end up with a 2^16 x 2^16 = 4.3 Gigapixel image and 15 triangle levels.

matlab 56
v=[1;-1;j];plot(filter(1,[1,-.5],v(randi(3,1,1e4))),'.')

APL, 37 32 (28 23)
Upright triangle (37 32-char)
({((-1⌷⍴⍵)⌽⍵,∊⍵)⍪⍵,⍵}⍣⎕)1 2⍴'/\'

Explanation

1 2⍴'/\': Create a 1×2 character matrix /\
{((-1⌷⍴⍵)⌽⍵,∊⍵)⍪⍵,⍵}: A function that pad the right argument on both sides with blanks to create a matrix double as wide, then laminates the right argument itself doubled onto the bottom.
E.g. /\ would become

 /\
/\/\

⍣⎕: Recur the function (user input) times.

Example output
               /\
              /\/\
             /\  /\
            /\/\/\/\
           /\      /\
          /\/\    /\/\
         /\  /\  /\  /\
        /\/\/\/\/\/\/\/\
       /\              /\
      /\/\            /\/\
     /\  /\          /\  /\
    /\/\/\/\        /\/\/\/\
   /\      /\      /\      /\
  /\/\    /\/\    /\/\    /\/\
 /\  /\  /\  /\  /\  /\  /\  /\
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\

Skewed Triangle (28 23-char)
({(⍵,∊⍵)⍪⍵,⍵}⍣⎕)1 1⍴'○'

Explaination

1 1⍴'○': Create a 1×1 character matrix ○
{(⍵,∊⍵)⍪⍵,⍵}: A function that pad the right argument on the right with blanks to create a matrix double as wide, then laminates the right argument itself doubled onto the bottom.
E.g. ○ would become

○
○○

⍣⎕: Recur the function (user input) times.

Example output
○
○○
○ ○
○○○○
○   ○
○○  ○○
○ ○ ○ ○
○○○○○○○○
○       ○
○○      ○○
○ ○     ○ ○
○○○○    ○○○○
○   ○   ○   ○
○○  ○○  ○○  ○○
○ ○ ○ ○ ○ ○ ○ ○
○○○○○○○○○○○○○○○○

Logo, 75 characters
59 characters for just the first function, the second one calls the first with the size and the depth/number of iterations. So you could just call the first function from the interpreter with the command: e 99 5, or whatever size you want to output
to e :s :l
if :l>0[repeat 3[e :s/2 :l-1 fd :s rt 120]]
end
to f
e 99 5
end

+1 I've read about Logo. What interpreter are you using? ... Logo might be a natural fit for my l-system challenge.

If you just remove the to f and end around e 99 5, you have a complete runnable program in fewer characters.  Also, in UCBLogo (though not other versions) you can lose the colons on the variables to save more chars.

Mathematica  63
ListPlot@ReIm@NestList[#/2+RandomChoice[{0,1,-1}^(1/3)]&,0.,8!]

Mathematica  67
Region@Polygon@ReIm@Nest[Tr/@Tuples[{p,#}/2]&,{p={0,1,-1}^(1/3)},6]

Python (90 chars)
from turtle import*
def l():left(60)
def r():right(60)
def f():forward(1)
def L(n):
 if n:n-=1;R(n);l();L(n);l();R(n)
 else:f()
def R(n):
 if n:n-=1;L(n);r();R(n);r();L(n)
 else:f()
l();L(8)

Try it online
Draw fractal line filling Sierpinsky Triangle

Before running, I recommend inserting ht();speed(0);up();goto(20-window_width()/2, 20-window_height()/2);down() after the import. This will run it much faster and ensure that the output fits on the canvas.

J (18 characters)
' *'{~(,,.~)^:9 ,1

Result
*
**
* *
****
*   *
**  **
* * * *
********
*       *
**      **
* *     * *
****    ****
*   *   *   *
**  **  **  **
* * * * * * * *
****************
*               *
**              **
* *             * *
****            ****
*   *           *   *
**  **          **  **
* * * *         * * * *
********        ********
*       *       *       *
**      **      **      **
* *     * *     * *     * *
****    ****    ****    ****
*   *   *   *   *   *   *   *
**  **  **  **  **  **  **  **
* * * * * * * * * * * * * * * *
********************************

Asymptote, 152 bytes
I'll add this, mostly since I've seen more or less no answers in asymptote on this site. A few wasted bytes for nice formatting and generality, but I can live with that. Changing A,B and C will change where the corners of the containing triangle are, but probably not in the way you think. Increase the number in the inequality to increase the depth.
pair A=(0,0),B=(1,0),C=(.5,1);void f(pair p,int d){if(++d<7){p*=2;f(p+A*2,d);f(p+B*2,d);f(p+C*2,d);}else{fill(shift(p/2)*(A--B--C--cycle));}}f((0,0),0);

or ungolfed and readable
pair A=(0,0), B=(1,0), C=(.5,1);

void f(pair p, int d) {
    if (++d<7) {
        p *= 2;
        f(p+A*2,d);
        f(p+B*2,d);
        f(p+C*2,d);
    } else {
        fill(shift(p/2)*(A--B--C--cycle));
    }
}

f((0,0),0);

So asymptote is a neat vector graphics language with somewhat C-like syntax. Quite useful for somewhat technical diagrams. Output is of course in a vector format by default (eps, pdf, svg) but can be converted into basically everything imagemagick supports. Output:

APL (Dyalog Classic), 12 bytes
×.≥∘⍉⍨↑,⍳⎕⍴2

Try it online!

Mathematica, 29 bytes
Image@Array[BitAnd,{2,2}^9,0]

The Sierpinski tetrahedron can be drawn in a similar way:
Image3D[1-Array[BitXor,{2,2,2}^7,0]]

J, 37 35 bytes
-2 bytes thanks to FrownyFrog
(,.~,~' '&,.^:#)@[&0' /\',:'/__\'"_

Try it online!
This is Peter Taylor's ascii art version converted to J.  Could save bytes with a less pretty version, but why?
       /\
      /__\
     /\  /\
    /__\/__\
   /\      /\
  /__\    /__\
 /\  /\  /\  /\
/__\/__\/__\/__\

@]^:[ -> @[&0 and ' /\ ' -> ' /\'

Do you happen to know where &0 trick is documented?

Mentioned here at the bottom of the page. While it saves a byte you lose the ability to have negative number of repeats.

Oh, you should be able to swap the operands to ,~ around.

Lua script in Golly, 54 bytes
g=golly()
g.setrule("W60")
g.setcell(0,0,1)
g.run(512)

Golly is a cellular automata simulator with Lua and Python scripting support.
This script sets the rule to Wolfram Rule 60, sets the cell at (0,0) to 1, and runs 512 steps.

05AB1E, 9 bytes
1=IGx^Db,

Try it online!
The number of rows is equal to the input.
Explanation:
1=IGx^Db,
1=         print "1" and push 1
  IG       for N in range(1, I): (where I is the input)
    x      push last element on stack multiplied by 2
     ^     pop last two elements, push their bitwise xor (output is in decimal)
      D    duplicate last element of stack
       b,  replace last element of stack with its binary representation, then print/pop

This takes advantage of the fact that a(n+1) = a(n) XOR 2*a(n), which I found on this relevant OEIS page

Look ma, no unicode!!!

8086 Machine code - 18 bytes (unknown author) / 27 bytes (mine)
In early 1990s, I organized a small competition on programmer's board on a Croatian BBS, who can write the smallest program to draw the Sierpinski triangle.
My best solution was 27 bytes long, but there were several even smaller and unique solutions, with smallest one being only 18 bytes of machine code. Unfortunately, I forgot the name of the person who wrote it - so if the original author is reading this, please contact me. :)

18 bytes solution by an unknown Croatian programmer:
Bytes: B0 13 CD 10 B5 A0 8E D9 30 84 3F 01 AC 32 04 E2 F7 C3

0100 B013          MOV     AL,13
0102 CD10          INT     10
0104 B5A0          MOV     CH,A0
0106 8ED9          MOV     DS,CX
0108 30843F01      XOR     [SI+013F],AL
010C AC            LODSB
010D 3204          XOR     AL,[SI]
010F E2F7          LOOP    0108
0111 C3            RET

Which draws this:

My 27 bytes solution:
Bytes: B0 13 CD 10 B7 A0 8E C3 8E DB BF A0 00 AA B9 C0 9E BE 61 FF AC 32 04 AA E2 FA C3

0100 B013          MOV     AL,13
0102 CD10          INT     10
0104 B7A0          MOV     BH,A0
0106 8EC3          MOV     ES,BX
0108 8EDB          MOV     DS,BX
010A BFA000        MOV     DI,00A0
010D AA            STOSB
010E B9C09E        MOV     CX,9EC0
0111 BE61FF        MOV     SI,FF61
0114 AC            LODSB
0115 3204          XOR     AL,[SI]
0117 AA            STOSB
0118 E2FA          LOOP    0114
011A C3            RET

Which draws this:

Postscript, 205 203
[48(0-1+0+1-0)49(11)43(+)45(-)/s{dup
0 eq{exch{[48{1 0 rlineto}49 1 index
43{240 rotate}45{120 rotate}>>exch
get exec}forall}{exch{load
exch 1 sub s}forall}ifelse 1 add}>>begin
9 9 moveto(0-1-1)9 s fill

Rewrite using strings and recursion ends up at exactly the same count. But the depth-limitations of the macro-approach are overcome.
Edit: fill is shorter than stroke.
Indented and commented.
%!
[   % begin dictionary
    48(0-1+0+1-0) % 0
    49(11)        % 1
    43(+)         % +
    45(-)         % -
    /s{ % string recursion-level
        dup 0 eq{ % level=0
            exch{  % iterate through string
                [
                    48{1 0 rlineto} % 0
                    49 1 index      % 1
                    43{240 rotate}  % +
                    45{120 rotate}  % -
                >>exch get exec % interpret turtle command
            }forall
        }{ % level>0
            exch{  % iterate through string
                load exch  % lookup charcode
                1 sub s    % recurse with level-1
            }forall
        }ifelse
        1 add  % return recursion-level+1
    }
>>begin
9 9 moveto(0-1-1)9 s fill % execute and fill

Adding 0 setlinewidth gives a better impression of how deep this one goes.

This one's my favorite.

There's a way to make it shorter with this external lib that I wrote after the fact and cannot use. :P

C, 106 chars
i,j;main(){for(;i<32;j>i/2?puts(""),j=!++i:0)
printf("%*s",j++?4:33-i+i%2*2,i/2&j^j?"":i%2?"/__\\":"/\\");}

(It still amuses me that puts("") is the shortest way to output a newline in C.)
Note that you can create larger (or smaller) gaskets by replacing the 32 in the for loop's test with a larger (smaller) power of two, as long as you also replace the 33 in the middle of the printf() with the power-of-two-plus-one.

Suggest j>i/2&&puts("",j=!++i) instead of j>i/2?puts(""),j=!++i:0

6502 ASM,  134 bytes
start:
lda #$e1
sta $0
lda #$01
sta $1
ldy #$20
w_e:
ldx #$00
eor ($0, x)
sta ($0),y
inc $0
bne w_e
inc $1
ldx $1
cpx #$06
bne w_e
rts

Pretty simple. Displays the triangles. Note that the top and left sides of the image are invisible due to the white background of PPCG.

Haskell, 166 154 bytes
(-12 bytes thanks to Laikoni, (zip and list comprehension instead of zipWith and lambda, better way of generating the first line))
i#n|let k!p=p:(k+1)![m*l*r+(m*(l*r-l-r)+1)*0^mod k(2^(n-i))|(l,m,r)<-zip3(1:p)p$tail p++[1]];x=1<$[2..2^n]=mapM(putStrLn.map("M "!!))$take(2^n)$1!(x++0:x)

Try it online!
Explanation:
The function i#n draws an ASCII-Triangle of height 2^n after i steps of iteration.
The encoding used internally encodes empty positions as 1 and full positions as 0. Therefore, the first line of the triangle is encoded as [1,1,1..0..1,1,1] with 2^n-1 ones on both sides of the zero. To build this list, we start with the list x=1<$[2..2^n], i.e. the list [2..2^n] with everything mapped to 1. Then, we build the complete list as x++0:x
The operator k!p (detailed explanation below), given a line index k and a corresponding p generates an infinite list of lines that follow p. We invoke it with 1 and the starting line described above to get the entire triangle, and then only take the first 2^n lines. Then, we simply print each line, replacing 1 with space and 0 with M (by accessing the list "M " at location 0 or 1).
Operator k!p is defined as follows:
k!p=p:(k+1)![m*l*r+(m*(l*r-l-r)+1)*0^mod k(2^(n-i))|(l,m,r)<-zip3(1:p)p$tail p++[1]]

First, we generate three versions of p: 1:p which is p with a 1 prepended, p itself and tail p++[1] which is everything but the first element of p, with a 1 appended. We then zip these three lists, giving us effectively all elements of p with their left and right neighbors, as (l,m,r). We use a list comprehension to then calculate the corresponding value in the new line:
m*l*r+(m*(l*r-l-r)+1)*0^mod k(2^(n-i))

To understand this expression, we need to realise there are two basic cases to consider: Either we simply expand the previous line, or we are at a point where an empty spot in the triangle begins. In the first case, we have a filled spot if any of the spots in the neighborhood is filled. This can be calculated as m*l*r; if any of these three is zero, then the new value is zero. The other case is a bit trickier. Here, we basically need edge detection. The following table gives the eight possible neighborhoods with the resulting value in the new line:
000 001 010 011 100 101 110 111
 1   1   1   0   1   1   0   1

A straightforward formula to yield this table would be 1-m*r*(1-l)-m*l*(1-r) which simplifies to m*(2*l*r-l-r)+1. Now we need to choose between these two cases, which is where we use the line number k. If mod k (2^(n-i)) == 0, we have to use the second case, otherwise, we use the first case. The term 0^(mod k(2^n-i)) therefore is 0 if we have to use the first case and 1 if we have to use the second case. As a result, we can use
m*l*r+(m*(l*r-l-r)+1)*0^mod k(2^(n-i))

in total - if we use the first case, we simply get m*l*r, while in the second case, an additional term is added, giving the grand total of m*(2*l*r-l-r)+1.

154 bytes: Try it online! Nice explanation by the way!

@Laikoni Ooh, some very nice improvements in there!

Python (215 209)
Uses the Chaos Theory method of generating Sierpinski's Triangle.
import random as r,pygame as p
d=p.display
x=99;X=49;y=x,x
s=d.set_mode(y)
c=[X,X]
P=(X,0),(0,x),y
while 1:
 a=r.choice(P)
 for i in 0,1:c[i]=(c[i]+a[i])/2
 p.draw.rect(s,[x]*3,p.Rect(c[0],c[1],2,2))
 d.flip()

JavaScript (70 chars):
for(y=32;y--;){for(s="",x=32;x--;)s+=(x-y/2)&y?" ":"o";console.log(s)}

Using HTML guy's method. This feels like cheating, though. He gets the thread.
               oo
               oo
              o oo
              oooo
             o   oo
             oo  oo
            o o o oo
            oooooooo
           o       oo
           oo      oo
          o o     o oo
          oooo    oooo
         o   o   o   oo
         oo  oo  oo  oo
        o o o o o o o oo
        oooooooooooooooo
       o               oo
       oo              oo
      o o             o oo
      oooo            oooo
     o   o           o   oo
     oo  oo          oo  oo
    o o o o         o o o oo
    oooooooo        oooooooo
   o       o       o       oo
   oo      oo      oo      oo
  o o     o o     o o     o oo
  oooo    oooo    oooo    oooo
 o   o   o   o   o   o   o   oo
 oo  oo  oo  oo  oo  oo  oo  oo
o o o o o o o o o o o o o o o oo
oooooooooooooooooooooooooooooooo

Common Lisp, 80 chars
(#1=dotimes(i 32)(#1#(j 32)(princ(if(logtest(- j(ash i -1))i)' 'Δ)))(terpri))

Output:
ΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔ
Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ Δ
 ΔΔ  ΔΔ  ΔΔ  ΔΔ  ΔΔ  ΔΔ  ΔΔ  ΔΔ
 Δ   Δ   Δ   Δ   Δ   Δ   Δ   Δ
  ΔΔΔΔ    ΔΔΔΔ    ΔΔΔΔ    ΔΔΔΔ
  Δ Δ     Δ Δ     Δ Δ     Δ Δ
   ΔΔ      ΔΔ      ΔΔ      ΔΔ
   Δ       Δ       Δ       Δ
    ΔΔΔΔΔΔΔΔ        ΔΔΔΔΔΔΔΔ
    Δ Δ Δ Δ         Δ Δ Δ Δ
     ΔΔ  ΔΔ          ΔΔ  ΔΔ
     Δ   Δ           Δ   Δ
      ΔΔΔΔ            ΔΔΔΔ
      Δ Δ             Δ Δ
       ΔΔ              ΔΔ
       Δ               Δ
        ΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔ
        Δ Δ Δ Δ Δ Δ Δ Δ
         ΔΔ  ΔΔ  ΔΔ  ΔΔ
         Δ   Δ   Δ   Δ
          ΔΔΔΔ    ΔΔΔΔ
          Δ Δ     Δ Δ
           ΔΔ      ΔΔ
           Δ       Δ
            ΔΔΔΔΔΔΔΔ
            Δ Δ Δ Δ
             ΔΔ  ΔΔ
             Δ   Δ
              ΔΔΔΔ
              Δ Δ
               ΔΔ
               Δ

JavaFx, 400 bytes
import javafx.scene.*;import javafx.scene.canvas.*;public class S extends javafx.application.Application{public void start(javafx.stage.Stage s){Canvas v=new Canvas(640,640);int[]xs={320,0,640},ys={0,640,640};for(int i=0,x=0,y=0,n=0;i<999999;i++){n=new java.util.Random().nextInt(3);v.getGraphicsContext2D().fillRect(x+=(xs[n]-x)/2,y+=(ys[n]-y)/2,1,1);}s.setScene(new Scene(new Group(v)));s.show();}}

Operates via the move-halfway-to-a-random-vertex method. 999,999 iterations, 640x640 canvas. I could have golfed a few more bytes by reducing the size or the number of iterations, but when you're at 400 bytes what's the point? No one wants to look at postage stamp-sized output.

Ungolfed, mostly:
import javafx.scene.*;
import javafx.scene.canvas.*;

public class S extends javafx.application.Application {
    public void start(javafx.stage.Stage s) {
        Canvas v = new Canvas(640, 640);
        int[] xs = {320,0,640}, ys = {0,640,640};
        for (int i=0, x=0, y=0, n=0; i < 999999; i++) {
            n = new java.util.Random().nextInt(3);
            v.getGraphicsContext2D().fillRect(
                x += (xs[n]-x)/2, y += (ys[n]-y)/2, 1, 1);
        }
        s.setScene(new Scene(new Group(v)));
        s.show();
    }
}

JavaFx has a very annoying way of putting every class you might want to use in separate javafx.application, javafx.stage, javafx.scene, javafx.canvas packages. Grr!

Can't you use 1e6 for number of iterations

@ASCII-only Good idea!

Pyt, 19 bytes
02⁵ř↔Á`⁻Đ0⇹Řć2%ǰƥłŕ

Result:
1
11
101
1111
10001
110011
1010101
11111111
100000001
1100000011
10100000101
111100001111
1000100010001
11001100110011
101010101010101
1111111111111111
10000000000000001
110000000000000011
1010000000000000101
11110000000000001111
100010000000000010001
1100110000000000110011
10101010000000001010101
111111110000000011111111
1000000010000000100000001
11000000110000001100000011
101000001010000010100000101
1111000011110000111100001111
10001000100010001000100010001
110011001100110011001100110011
1010101010101010101010101010101
11111111111111111111111111111111

Explanation:
0                        Push 0
 2⁵                      Push 32
   ř↔                    Pop 32, and push [32,31,30,29,...,3,2,1]
     Á                   Push contents of array onto stack
      `          ł       While the top of the stack is not zero, loop:
       ⁻                 Decrement the number at the top of the stack
        Đ0⇹Řć2%ǰƥ        Calculate the kth row of Pascal's Triangle mod 2 and print
                  ŕ      Remove the 0

Try it online!

asm2bf, 219 bytes
Code
@a
clrr2
@b
pshr1
movr4,r2
@c
movr5,r1
modr5,2
movr6,r4
modr6,2
mulr5,r6
cger5,1
cmor5,1
cjn%d
asrr1
asrr4
jnzr1,%c
jnzr4,%c
clrr3
@d
cger3,1
movr3,42
cmor3,32
outr3
popr1
incr2
cger2,64
cjz%b
out10
incr1
cger1,64
cjz%a

The output

Applesoft BASIC, 246 bytes
1 HGR:HCOLOR=3:HOME:DIM x(3),y(3):x(0)=0:y(0)=160:x(1)=90:y(1)=0:x(2)=180:y(2)=160:FOR i=0 to 2:HPLOT x(i),y(i):NEXT i
2 x=int(RND(1)*180):y=int(RND(1)*150):HPLOT x,y:FOR i=1 to 2000:v=int(rnd(1)*3):x=(x+x(v))/2:y=(y+y(v))/2:HPLOT x,y:NEXT:GOTO 2

Not the most efficient, nor does it draw a perfect Sierpinski, but it's fun. May stick pixels in random places or miss a few points depending on your system's pRNG quality.

Ungolfed:
100 HGR : HCOLOR=3 : HOME
110 REM set up three points to form a triangle
120 DIM x(3), y(3)
130 x(0) = 0 : y(0) = 160
140 x(1) = 90 : y(1) = 0
150 x(2) = 180 : y(2) = 160
160 REM plot the vertices of the triangle
170 FOR i= 0 to 2
180 HPLOT x(i), y(i)
190 NEXT i
200 REM pick a random starting point
210 x = int(RND(1)*180) : y = int(RND(1)*150)
220 hplot x,y
230 FOR i = 1 to 2000
240 REM randomly pick one of the triangle vertices
250 v = int(rnd(1)*3)
260 REM move the point half way to the triangle vertex
270 x = (x + x(v)) / 2 : y = (y + y(v)) / 2
280 HPLOT x,y
290 NEXT

Bash (94 chars)
Copyed from the html guy of this thread
for((y=64;y--;));do s="";for((x=64;x--;));do(((x-y/2)&y))&&s+=" "||s+="Δ";done;echo "$s";done

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Words from periodic table of elements
Back when I was a freshman in highschool taking chemistry, I'd look at the periodic table of elements and spell dirty words out with the number of the elements (HeCK would be 2619, 2-6-19).
I was thinking about this the other day when I saw an amazing shirt that spelled out BeEr (4-68)
So my codegolf challenge is shortest program to output a list of words you can spell with the periodic table of elements AND the number code that would represent that word.
/usr/share/dict/words or whatever dictionary you want to use for the word list. If you're using a "non-standard" word list, let us know what it is!

'The' number code? What about cases where there's more than one? E.g. CO vs Co.

I guess it depends on your code. Both are valid.

As I'm reading the responses below, I noticed one place that everybody could cut out a few characters. They might remove Co, Si, Sc, Os, Hs, Po, Pb, Np, No, Yb, Cs, and maybe others from their list of elements, since they can all be constructed from other elements.

@PhiNotPi, I considered dropping elements which aren't used, but that one's arguable because someone might want to use a different word list (or even one from a different language). I think I could get away with reducing the elements you suggest to one character each.

Not Ytterbium, that's my favorite element!

Just to clarify, the elements that I listed can always be safely removed. For example, Ytterbium can always be replaced with a Yttrium and a Boron, no matter what language the word list is in.

I'm not quite sure whether I understand the task completely: Shall we find matching words for the elements until every element was printed, or shall we print every word from the dict, which can be combined from the element table? Or something else?

Every word that can made from the elements that is in the dictionary. Elements can and will have to repeat.

@Rob: I would have received a notification about your comment, if you had tagged it with an @ sign, and my name. While typing the first characters of a name, you get a suggestion to complete it with TAB. The original writer of a Q or A doesn't need to be tagged - he gets informed automatically.

GolfScript (339 303 302 301 294 chars)
n/{{{32|}%}:L~['']{{`{\+}+'HHeLiBeBCNOFNeNaMgAl
PSClArKCa TiVCrMnFe

ZnGaGeAsSeBrKrRbSrYZr
MoTcRuRhPdAgCd

TeIXe
BaLaCePrNdPmSmEuGdTbDy
ErTm
Lu
TaWRe
IrPtAuHgTl

AtRnFrRaAcThPaU

AmCm

EsFmMd
LrRfDbSg

MtDsRg
UutFl
Lv'{[1/{.0=96>{+}*}/]}:S~:^/}%.{L}%2$?.){=S{^?}%`+p 0}{;{L.,2$<=},.}if}do}%;

With credit to PhiNotPi whose observation on unnecessary elements allowed me to save 33 chars.
This is IMO much more idiomatic GolfScript than the previous recursive approach.
Note that I allow words in the dictionary to be mixed case (L is a function to lower-case text on the assumption that it doesn't matter if non-alpha characters get broken) but reject any with apostrophes or accents.
Since this is code golf, I've optimised for code length rather than speed. This is horrendously slow. It expects the word list to be supplied at stdin and outputs to stdout in the format:
"ac[89]"
"accra[89 6 88]"
"achebe[89 2 4]"
...

(lower-casing any mixed-case input words for which it finds a match).
If you're more interested in the elements than the numbers per se, for the low low price of 261 253 chars you can use
n/{{{32|}%}:L~['']{{`{\+}+'HHeLiBeBCNOFNeNaMgAlPSClArKCaTiVCrMnFeZnGaGeAsSeBrKrRbSrYZrMoTcRuRhPdAgCdTeIXeBaLaCePrNdPmSmEuGdTbDyErTmLuTaWReIrPtAuHgTlAtRnFrRaAcThPaUAmCmEsFmMdLrRfDbSgMtDsRgUutFlLv'[1/{.0=96>{+}*}/]/}%.{L}%2$?.){=p 0}{;{L.,2$<=},.}if}do}%;

which gives output like
"Ac"
"AcCRa"
"AcHeBe"
...

Take the extra character out, " doesn't bother me at all. And of course peter taylor comes in and blows everyone away with golfscript.

Ruby - 547 393
New version, thanks for the suggestions:
e='HHeLiBeBCNOFNeNaMgAlSiPSClArKaCaScTiVCrMnFeCoNiCuZnGaGeAsSeBrKrRbSrYZrNbMoTcRuRhPdAgCdInSnSbTeIXeCsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaWReOsIrPtAuHgTlPbBiPoAtRnFrRaAcThPaUNpPuAmCmBkCfEsFmMdNoLrRfDbSgBhHsMtDsRgCnUutFlUupLvUusUuo'.scan(/[A-Z][a-z]*/).map &:upcase
r="(#{e.join ?|})"
$<.each{|w|(i=0;i+=1 until w=~/^#{r*i}$/i
$><<w;p$~.to_a[1..-1].map{|m|e.index(m.upcase)+1})if w=~/^#{r}+$/i}

e=%w{h he li be b c n o f ne na mg al si p s cl ar ka ca sc ti v cr mn fe co ni cu zn ga ge as se br kr rb sr y zr nb mo tc ru rh pd ag cd in sn sb te i xe cs ba la ce pr nd pm sm eu gd tb dy ho er tm yb lu hf ta w re os ir pt au hg tl pb bi po at rn fr ra ac th pa u np pu am cm bk cf es fm md no lr rf db sg bh hs mt ds rg cn uut fl uup lv uus uuo}
x = "(#{e.join(?|)})"
regex = /^#{x}+$/i
File.foreach('/usr/share/dict/words'){|w|
if w=~/^#{x}+$/i
puts w
i=1
i+=1 until w=~/^#{x*i}$/i
puts $~[1..-1].map{|m|e.index(m.downcase)+1}.join ?-
end
}

uses regexes. slow, and much room for improvement but i must go now :-)

You can spare storage by using Peter Taylor's trick (as in his original code): e='HHeLiBe...LvUusUuo'.scan(/[A-Z][a-z]*/).map &:downcase. 2) Variable regex is never used. 3) Read the words from standard input: $<.each{|w|.... With these modification the code got reduced to 410 characters.

I think that you can apply the same space-saving approach for unnecessary elements too, at the cost of adding two characters to the scan regex. Use space if you don't like newlines - I'm using newlines mainly so that it's not necessary to scroll to see the main loop.

Python 710 (357 + 261 + 92)
e=". h he li be b c n o f ne na mg al si p s cl ar k ca sc ti v cr mn fe co ni cu zn ga ge as se br kr rb sr y zr nb mo tc ru rh pd ag cd in sn sb te i xe cs ba la ce pr nd pm sm eu gd tb dy ho er tm yb lu hf ta w re os ir pt au hg tl pb bi po at rn fr ra ac th pa u np pu am cm bk cf es fm md no lr rf db sg bh hs mt ds rg cn uut fl uup lv uus uuo".split()

i=e.index
def m(w,p=("",[])):
 if not w:return p
 x,y,z=w[0],w[:2],w[:3]
 if x!=y and y in e:
    a=m(w[2:],(p[0]+y,p[1]+[i(y)]))
    if a:return a
 if x in e:
    b=m(w[1:],(p[0]+x,p[1]+[i(x)]))
    if b:return b
 if z in e:
    c=m(w[3:],(p[0]+z,p[1]+[i(z)]))
    if c:return c

f=open('/usr/share/dict/words','r')
for l in f:
 x=m(l[:-1])
 if x:print x[0],x[1]
f.close()

There's sure to be room for improvement in there somewhere. It's also worth noting that the second level of indentation uses the tab character.
It takes just over 5 seconds (on my computer) to go through the whole dictionary, producing output like this:
acaciin [89, 89, 53, 49]
acacin [89, 89, 49]
acalycal [89, 13, 39, 6, 13]
...

By adding another 18 characters, you can get output with the right capitalization:
e=". H He Li Be B C N O F Ne Na Mg Al Si P S Cl Ar K Ca Sc Ti V Cr Mn Fe Co Ni Cu Zn Ga Ge As Se Br Kr Rb Sr Y Zr Nb Mo Tc Ru Rh Pd Ag Cd In Sn Sb Te I Xe Cs Ba La Ce Pr Nd Pm Sm Eu Gd Tb Dy Ho Er Tm Yb Lu Hf Ta W Re Os Ir Pt Au Hg Tl Pb Bi Po At Rn Fr Ra Ac Th Pa U Np Pu Am Cm Bk Cf Es Fm Md No Lr Rf Db Sg Bh Hs Mt Ds Rg Cn Uut Fl Uup Lv Uus Uuo".split()

i=e.index
def m(w,p=("",[])):
 if not w:return p
 w=w.capitalize()
 x,y,z=w[0],w[:2],w[:3]
 if x!=y and y in e:
    a=m(w[2:],(p[0]+y,p[1]+[i(y)]))
    if a:return a
 if x in e:
    b=m(w[1:],(p[0]+x,p[1]+[i(x)]))
    if b:return b
 if z in e:
    c=m(w[3:],(p[0]+z,p[1]+[i(z)]))
    if c:return c

OUTPUT:

AcAcIIn [89, 89, 53, 49]
AcAcIn [89, 89, 49]
AcAlYCAl [89, 13, 39, 6, 13]
...

You can also check individual words:
>>> m("beer")
('beer', [4, 68])

Can you add the one that outputs proper capitalization?  I think that's pretty neat and I'm pretty new to python.

Python - 1328 (975 + 285 chars of code + 68 dictionary code)
t1={'c':6,'b':5,'f':9,'i':53,'h':1,'k':19,'o':8,'n':7,'p':15,
's':16,'u':92,'w':74,'v':23,'y':39}
t2={'ru':44,'re':75,'rf':104,'rg':111,'ra':88,'rb':37,
'rn':86,'rh':45,'be':4,'ba':56,'bh':107,'bi':83,
'bk':97,'br':35,'os':76,'ge':32,'gd':64,'ga':31,
'pr':59,'pt':78,'pu':94,'pb':82,'pa':91,'pd':46,
'cd':48,'po':84,'pm':61,'hs':108,'ho':67,'hf':72,
'hg':80,'he':2,'md':101,'mg':12,'mo':42,'mn':25,
'mt':109,'zn':30,'eu':63,'es':99,'er':68,'ni':28,
'no':102,'na':11,'nb':41,'nd':60,'ne':10,'np':93,
'fr':87,'fe':26,'fl':114,'fm':100,'sr':38,'kr':36,
'si':14,'sn':50,'sm':62,'sc':21,'sb':51,'sg':106,
'se':34,'co':27,'cn':112,'cm':96,'cl':17,'ca':20,
'cf':98,'ce':58,'xe':54,'lu':71,'cs':55,'cr':24,
'cu':29,'la':57,'li':3,'lv':116,'tl':81,'tm':69,
'lr':103,'th':90,'ti':22,'te':52,'tb':65,'tc':43,
'ta':73,'yb':70,'db':105,'dy':66,'ds':110,'at':85,
'ac':89,'ag':47,'ir':77,'am':95,'al':13,'as':33,
'ar':18,'au':79,'zr':40,'in':49}
t3={'uut':113,'uuo':118,'uup':115,'uus':117}
def p(s):
 o=0;b=0;a=[];S=str;l=S.lower;h=dict.has_key;L=len
 while o<L(s):
  D=0
  for i in 1,2,3:exec('if h(t%d,l(s[o:o+%d])) and b<%d:a+=[S(t%d[s[o:o+%d]])];o+=%d;b=0;D=1'%(i,i,i,i,i,i))
  if D==0:
   if b==3 or L(a)==0:return
   else:b=L(S(a[-1]));o-=b;a.pop()
 return '-'.join(a)

For the dictionary part:
f=open(input(),'r')
for i in f.readlines():print p(i[:-1])
f.close()

It is really shorter to use an explicit hash initialisation than to use an explicit array initialisation and turn it into an index-of hash?

I just used a dictionary for ease of use. Having an array of tuples would be a little more character costly. Although ordering the elements would be a good idea...

C, 775 771 chars
char*e[]={"h","he","li","be","b","c","n","o","f","ne","na","mg","al","si","p","s","cl","ar","k","ca","sc","ti","v","cr","mn","fe","co","ni","cu","zn","ga","ge","as","se","br","kr","rb","sr","y","zr","nb","mo","tc","ru","rh","pd","ag","cd","in","sn","sb","te","i","xe","cs","ba","la","ce","pr","nd","pm","sm","eu","gd","tb","dy","ho","er","tm","yb","lu","hf","ta","w","re","os","ir","pt","au","hg","tl","pb","bi","po","at","rn","fr","ra","ac","th","pa","u","np","pu","am","cm","bk","cf","es","fm","md","no","lr","rf","db","sg","bh","hs","mt","ds","rg","cn","uut","fl","uup","lv","uus","uu",0};
b[99],n;
c(w,o,l)char*w,*o,**l;{
    return!*w||!strncmp(*l,w,n=strlen(*l))&&c(w+n,o+sprintf(o,",%d",l-e+1),e)||*++l&&c(w,o,l);
}
main(){
    while(gets(b))c(b,b+9,e)&&printf("%s%s\n",b,b+9);
}

Input: Word per line, must be lowercase. usr/share/dict/words is fine.
Output: Word and numbers, e.g.: acceptances,89,58,15,73,7,6,99
Logic:
c(w,o,l) checks the word w, starting with element l.
Two-way recursion is used - if the first element matches the head of the element list, check the remainer of w against the full element list. If this match fails, check the word against the tail of the list.
The buffer o accumulates the element numbers along the successful path. After a match, it will contain the list of numbers, and is printed.
Issues:
The list isn't encoded efficiently - too much " and ,". But this way it's easy to use. I'm sure it can be much improved, without too much cost in code.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Line through Polygon
Input: A line of the standard slope-and-intercept form: mx+b, as well as a set of Cartesian points determining the vertices of a polygon. Assume that the x and y values of the points will be integers.
Output: A boolean, which is true if the line enters or touches the polygon, and is false otherwise.
This is a little tricky, so I'll give a clue: turn the vertices that determine an edge into lines.
Test Cases
2x+3 (1,2) (2,5) (5,10) -> False
5x+0 (5,10) (2,10) (2,-10) (5,-10) -> True
0.5x+3.1 (1, 2), (-1, 2), (5, 8), (6, 7), (2, 10) -> True
Shortest or most creative code wins. I don't know too many languages, so explain your algorithm in your post. Good luck!

Related: http://codegolf.stackexchange.com/q/2057/78 and http://codegolf.stackexchange.com/q/1529/78 . And for some reason it made me think of http://codegolf.stackexchange.com/questions/2509/1p5-earthquake , though I don't think these if much actual commonality.

Is it guaranteed that the polygons have integer-only vertices?

For simplicity, yes. Added that to the Input section.

Why would you want to turn the vertices into edges? The simplest algorithm is to test whether all vertices are on the same side of the line or not.

@beary: I suppose the vertices are given in order, right?

Peter Taylor: well, that was my take on the solution, it may not be the best. Eelvex: Yeah.

J, 80 characters
('True';'False'){~*/2=/\0>_2(]-1{y+0{y*[)/\2}.[y=.".'-_x + ( , ) 'charsub 1!:1[1

Takes input from the keyboard in the format specified in the question. It uses the algorithm suggested by Peter Taylor in the comments to the question.
Explanation (bearing in mind that J is read from right to left):
1!:1[1 waits for a line of input from the keyboard.
'-_x + ( , ) 'charsub replaces all occurances of x,+,(,, and ) with a space and replaces - with _. This turns the input into a list of numbers (with _ in front of the negative numbers as required for J).
". reads in the list as an array instead of a string.
y=. assigns the list to the variable y.
2}. removes the first 2 elements of the list.
_2(...)/\ takes each pair of numbers and applies the verb in the brackets to them.
]-1{y+0{y*[ calculates mx+c with the x from this pair of numbers and takes the result out of the y from this pair of numbers.
0> checks if each returned number is less than 0.
At this point we have a list of 1s and 0s depending on whether each point is above or below the line.
2=/\ takes each pair and checks if they are equal.
Now, if all points are on the same side of the line we have all 1s otherwise there are 0s in there somewhere.
*/ multiplies all the 1s and 0s together.
Now we have 0 if the points fall on both sides of the line and 1 and they all fall on the same side of the line.
{~ uses the 1 or 0 as an index into the list ('True';'False') returning the required output.

Ruby, 103 101 characters
m,b,*q=gets.scan(/[\d\.]+/).map{|t|t.to_f}
s=t=!0
q.each_slice(2){|x,y|x=x*m+b;s|=x<=y;t|=x>=y}
p s&t

Input is on STDIN in the form specified in the question while output goes to STDOUT.

Scala 255: 224
object P extends App{
val(m,p)=(args(0).split("[^0-9-.]").filter(!_.isEmpty)).map(_.toFloat)splitAt 2
def v(l:Array[Float])=(l(1)-m(0)*l(0)-m(1))*(l(3)-m(0)*l(2)-m(1))<=0
println((p.drop(p.size-2)++p).sliding(4,2) exists v)}

Using splitAt, inspired by Howard. :) Before:
object P extends App{
val f=args(0).split("[^0-9-.]").filter(!_.isEmpty)
val m=f.take(2).map(_.toFloat)
val p=f.drop(2).map(_.toInt)
def v(l:Array[Int])=(l(1)-m(0)*l(0)-m(1))*(l(3)-m(0)*l(2)-m(1))<=0
println((p.drop(p.size-2)++p).sliding(4,2).exists(v))
}

How:
val f=args(0).split("[^0-9-.]").filter(!_.isEmpty)

Line 2 just splits and filters away everything which isn't part of float or int, since we don't need '(' and ',' and such to identify our parameters - position is enough.
m is shorthand for mn in m*x+n, the values m and n are floats.
p is the polygon values.
v is the verify function

Assume we have f(x) = mx + n and the line pq:
               f(x)=mx+n
 |            /
 |          / |
 |p  *'--,,'  |
 |   |   / ''-* q
 |   | /
 |   /
 | /
 /___________________

f(x) crosses only by random the origin in this example. For the two points of the polygon p and q we can for px calculate f(px) and it can lay to the south or to the north of py, the real value of the polygon, or lay exactly on it.
If both calculated values f(px) and f(qx) are on the same side, north or south, the line doesn't cross.
So we have two values for the function:
val a = m*px+n
val b = m*qx+n

if (a == py || b == qy) the function line touches one of the points.
if ((a < py && b > py) || (a > py && b < py)) they are on different sides, and cross as well. We can express this by substracting:
d1 = py - a
d2 = qy - b

if (( d1 == 0 || d2 == 0 || (sign (d1) != sign(d2))) ...

If the signs are different, the multiplication will return a negative value, and if they match, it returns a positive value. If one of the values is 0, the product is null. So we can condense the whole question to:
d1 * d2 <= 0

And that's what the verify-method v does.
The values of the polygon are (x1, y1), (x2, y2), ...(xn, yn), but they are flattened to x1, y1, x2, y2, ...xn, yn. The drop-statement takes the last 2 of them and prepends them to the front, to build a closed shape (xn, yn -> x1, y1). Sliding (4, 2) takes 4 values and advances for a step size of 2 through the collection. If a pair of xy exists, for which the verify function returns true, the line crosses the polygon or touches it.
Now I have to understand why the Ruby solution is so much shorter. Okay - a few less type declarations, shorter conversions. No println, no object, no App. Similar approach.
Invocation:
 scala P "0.5x+3.1 (1, 2), (-1, 2), (5, 8), (6, 7), (2, 10)"

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Solve the Magic Hexagon
A magic hexagon is a hexagon where every row and every diagonal add up to the same value. In this case the value is 38. Each number from 1 to 19 must be used exactly once.

This image shows a solution but I want a program that derives this result.
Your challenge is to solve the magic hexagon as fast as possible. You must derive the result yourself, no hard-coding.

I suppose it's also a requirement that each of the values 1-19 be used exactly once?

Ya sorry I left that out by accident.

There are 19 variables and 15 linear constraints, so the most efficient way of computing them is likely to be to convert the system of equations into reduced row echelon form, identify 4 independent variables which you can use for a basis, and enumerate the 93024 combinations checking for ones which use 1-19 once each.

@Peter: Some of the constraints are redundant, so there are actually 7 independent variables.

How might the length of code not matter, and meanwhile the shorter the better? What is meant with most efficient? Lowest network traffic, size on HDD, size in RAM or highest speed? If highest speed: Shall we assume a multi core system, or a single CPU?

I'm closing this challenge, since the winning criterion is unclear and contradictory. The challenge is tagged [tag:cod-golf] which implies that the shortest code wins, but you say that code length doesn't matter. So if you want an efficient solution, this should be tagged [tag:fastest-code] or [tag:fastest-algorithm]. But which is it? And how is efficiency going to be measured?

C++
Uses some macros to enumerate the possible values.  (A-S, assigned lexicographically in the problem image.)  m is a bitmask of values that have been used so far.
#include <stdio.h>
#define LOOP(V) for(int V=1;V<20;V++){if(m&1<<V){m&=~(1<<V);
#define ENDLOOP(V) m|=1<<V;}}
#define SET(V,e) int V=e;if(m&1<<V){m&=~(1<<V);
#define UNSET(V) m|=1<<V;}
int main() {
  int m=1048574;
  LOOP(A);
  LOOP(B);
  SET(C,38-A-B);
  LOOP(D);
  SET(H,38-A-D);
  LOOP(G);
  SET(L,38-C-G);
  LOOP(E);
  SET(F,38-D-E-G);
  LOOP(I);
  SET(M,38-B-E-I);
  SET(Q,38-H-M);
  LOOP(J);
  SET(N,38-C-F-J-Q);
  SET(R,38-D-I-N);
  SET(S,38-Q-R);
  SET(P,38-L-S);
  SET(K,38-B-F-P);
  SET(O,38-M-N-P);
  printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S);
  UNSET(O);
  UNSET(K);
  UNSET(P);
  UNSET(S);
  UNSET(R);
  UNSET(N);
  ENDLOOP(J);
  UNSET(Q);
  UNSET(M);
  ENDLOOP(I);
  UNSET(F);
  ENDLOOP(E);
  UNSET(L);
  ENDLOOP(G);
  UNSET(H);
  ENDLOOP(D);
  UNSET(C);
  ENDLOOP(B);
  ENDLOOP(A);
}

Runs in 30msec and generates the following:
3 17 18 19 7 1 11 16 2 5 6 9 12 4 8 14 10 13 15
3 19 16 17 7 2 12 18 1 5 4 10 11 6 8 13 9 14 15
9 11 18 14 6 1 17 15 8 5 7 3 13 4 2 19 10 12 16
9 14 15 11 6 8 13 18 1 5 4 10 17 7 2 12 3 19 16
10 12 16 13 4 2 19 15 8 5 7 3 14 6 1 17 9 11 18
10 13 15 12 4 8 14 16 2 5 6 9 19 7 1 11 3 17 18
15 13 10 14 8 4 12 9 6 5 2 16 11 1 7 19 18 17 3
15 14 9 13 8 6 11 10 4 5 1 18 12 2 7 17 16 19 3
16 12 10 19 2 4 13 3 7 5 8 15 17 1 6 14 18 11 9
16 19 3 12 2 7 17 10 4 5 1 18 13 8 6 11 15 14 9
18 11 9 17 1 6 14 3 7 5 8 15 19 2 4 13 16 12 10
18 17 3 11 1 7 19 9 6 5 2 16 14 8 4 12 15 13 10

The 4th line is the example solution.

It's interesting that all of the solutions are mirrors and rotations of each other. I suppose that implies that there is only one unique solution where the values add to 38. The question I have, is if there are any solutions with a sum value other than 38?

There aren't - just replace all the 38s with a variable in my code and loop over it.

@primo It's not possible for a magic square/hexagon/whatever to have multiple solutions with different sums. Given the shape and the set of numbers, the required sum is fixed.

@primo, to expand on breadbox's comment, each cell participates in three lines: one East-West, one NorthEast-SouthWest, and one NorthWest-SouthEast. Therefore the total of the 15 lines is sum[1..19]*3, so each line sums to (19*20/2)*(3/15) = 38.

@PeterTaylor Thanks, that makes perfect sense.

Not a suggestion, but for my own curiosity: would using a constant (or a variable, I suppose) in place of the literal 38 have any impact on speed (understanding that 30ms is already blazingly fast), faster or slower?

@Gaffi: the replacement itself would only make it negligibly slower.  Looping over N different choices would make it N times slower, though.

So this somewhat ugly code crashes spectacularly in the REPL (its own words!), but compiles and executes fine.
Uppercase letters indicate values, I pick from the set to iterate over them. Lowercase letters are generated. z = 38 - X - Y for example, and e = 38 - X - A. With e and J we get n and so on.
/**
    X Y z
   A B c d
  e f g h i
   J k l m
    n o p
*/
object MagicHexagon extends App {

  val set =(1 to 19)toSet

  // row 1
  for (x <- set;
    y <-(set - x);
    z = 38 - y - x;
    dummy <- ((set - x - y) -- (set - x - y - z));
    rest1=(set - x - y - z);
    a <- rest1;
    e = 38 - x - a;
    dummy2 <- ((rest1 - a) -- (rest1 - a - e));
    j <- rest1 - a - e;
    n = 38 - e - j;
    dummy3 <- ((rest1 - a - e - j) -- (rest1 - a - e - j - n));
    b <- rest1 - a - e - n;
    rest2=(rest1 - a - e - j - n - b);
    f = 38 - y - b - j;
    dummy4 <- ((rest2) -- (rest2 - f));
    c <- rest2 - f;
    d = 38 - a - b - c;
    dummy5 <- ((rest2 - f - c) -- (rest2 - f - c - d));
    i = 38 - z - d;
    dummy6 <- ((rest2 - f - c - d) -- (rest2 - f - c - d - i));
    rest3 = rest2 - f - c - d - i;
    g <- rest3;
    h = 38 - e - f - g - i;
    dummy7 <- ((rest3 - g) -- (rest3 - g - h));
    k = 38 - z - c - g - n;
    dummy8 <- ((rest3 - g - h) -- (rest3 - g - h - k));
    o = 38 - a - f - k;
    rest4 = (rest3 - g - h - k - o);
    dummy9 <- ((rest3 - g - h - k) -- rest4);
    m = 38 - y - c - h;
    dummyA <- (rest4 -- (rest4 - m));
    p = 38 - i - m;
    dummyB <- (rest4 - m) -- (rest4 - m - p);
    l = 38 - j - k - m;
    dummyC <- (rest4 - m - p) -- (rest4 - m - p - l);
    buf = List( List("  ",x,y,z), List(" ",a,b,c,d), List("",e,f,g,h,i), List(" ",j,k,l,m), List("  ",n,o,p))) {
       println (buf.map (_.mkString ("", ", ", "")).mkString ("\n"))
      println ()
    }
}

The dummy-variables are a kind of hack to allow the loop to terminate prematurely if a generated value doesn't match one of the left values from the set, especially 0 or negative values must be avoided.
Result:
scala MagicHexagon
  , 10, 12, 16
 , 13, 4, 2, 19
, 15, 8, 5, 7, 3
 , 14, 6, 1, 17
  , 9, 11, 18

  , 10, 13, 15
 , 12, 4, 8, 14
, 16, 2, 5, 6, 9
 , 19, 7, 1, 11
  , 3, 17, 18

  , 9, 11, 18
 , 14, 6, 1, 17
, 15, 8, 5, 7, 3
 , 13, 4, 2, 19
  , 10, 12, 16

  , 9, 14, 15
 , 11, 6, 8, 13
, 18, 1, 5, 4, 10
 , 17, 7, 2, 12
  , 3, 19, 16

  , 3, 19, 16
 , 17, 7, 2, 12
, 18, 1, 5, 4, 10
 , 11, 6, 8, 13
  , 9, 14, 15

  , 3, 17, 18
 , 19, 7, 1, 11
, 16, 2, 5, 6, 9
 , 12, 4, 8, 14
  , 10, 13, 15

  , 18, 11, 9
 , 17, 1, 6, 14
, 3, 7, 5, 8, 15
 , 19, 2, 4, 13
  , 16, 12, 10

  , 18, 17, 3
 , 11, 1, 7, 19
, 9, 6, 5, 2, 16
 , 14, 8, 4, 12
  , 15, 13, 10

  , 16, 19, 3
 , 12, 2, 7, 17
, 10, 4, 5, 1, 18
 , 13, 8, 6, 11
  , 15, 14, 9

  , 16, 12, 10
 , 19, 2, 4, 13
, 3, 7, 5, 8, 15
 , 17, 1, 6, 14
  , 18, 11, 9

  , 15, 13, 10
 , 14, 8, 4, 12
, 9, 6, 5, 2, 16
 , 11, 1, 7, 19
  , 18, 17, 3

  , 15, 14, 9
 , 13, 8, 6, 11
, 10, 4, 5, 1, 18
 , 12, 2, 7, 17
  , 16, 19, 3

Runs in 17s on 7y'o' Laptop.

It takes 121 seconds to run and is incredibly inefficient.
Any tips to improve efficiency would be appreciated instead of down votes.
C#
static void Main(string[] args)
    {
        DateTime time = DateTime.Now;
        int n1 = 0, n2 = 0, n3 = 0, n4 = 0, n5 = 0, n6 = 0, n7 = 0, n8 = 0, n9 = 0, n10 = 0, n11 = 0, n12 = 0, n13 = 0, n14 = 0, n15 = 0, n16 = 0, n17 = 0, n18 = 0, n19 = 0;

            List<int> numbers = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
            List<int> c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19;

            c1 = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };

            for (int x1 = 0; x1 < c1.Count; x1++ )
            {
                n1 = c1[x1];
                c2 = c1.Select(i => i).ToList();
                c2.Remove(n1);
                for (int x2 = 0; x2 < c2.Count; x2++)
                {
                    n2 = c2[x2];
                    c3 = c2;
                    c3 = c2.Select(i => i).ToList();
                    c3.Remove(n2);
                    for (int x3 = 0; x3 < c3.Count; x3++)
                    {
                        n3 = c3[x3];

                        if (n1 + n2 + n3 == 38)
                        {
                            c4 = c3.Select(i => i).ToList();
                            c4.Remove(n3);
                            for (int x4 = 0; x4 < c4.Count; x4++)
                            {
                                n4 = c4[x4];
                                c5 = c4.Select(i => i).ToList();
                                c5.Remove(n4);
                                for (int x5 = 0; x5 < c5.Count; x5++)
                                {
                                    n5 = c5[x5];
                                    c6 = c5.Select(i => i).ToList();
                                    c6.Remove(n5);
                                    for (int x6 = 0; x6 < c6.Count; x6++)
                                    {
                                        n6 = c6[x6];
                                        c7 = c6.Select(i => i).ToList();
                                        c7.Remove(n6);
                                        for (int x7 = 0; x7 < c7.Count; x7++)
                                        {
                                            n7 = c7[x7];

                                            if(n4 + n5 + n6 + n7 == 38)
                                            {
                                                c8 = c7.Select(i => i).ToList();
                                                c8.Remove(n7);
                                                for (int x8 = 0; x8 < c8.Count; x8++)
                                                {
                                                    n8 = c8[x8];

                                                    if(n1 + n4 + n8 == 38)
                                                    {
                                                        c9 = c8.Select(i => i).ToList();
                                                        c9.Remove(n8);
                                                        for (int x9 = 0; x9 < c9.Count; x9++)
                                                        {
                                                            n9 = c9[x9];
                                                            c10 = c9.Select(i => i).ToList();
                                                            c10.Remove(n9);

                                                            for (int x10 = 0; x10 < c10.Count; x10++)
                                                            {
                                                                n10 = c10[x10];
                                                                c11 = c10.Select(i => i).ToList();
                                                                c11.Remove(n10);
                                                                for (int x11 = 0; x11 < c11.Count; x11++)
                                                                {
                                                                    n11 = c11[x11];
                                                                    c12 = c11.Select(i => i).ToList();
                                                                    c12.Remove(n11);

                                                                    for (int x12 = 0; x12 < c12.Count; x12++)
                                                                    {
                                                                        n12 = c12[x12];

                                                                        if(n8 + n9 + n10 + n11 + n12 == 38)
                                                                        {
                                                                            if(n3 + n7 + n12 == 38)
                                                                            {
                                                                                c13 = c12.Select(i => i).ToList();
                                                                                c13.Remove(n12);
                                                                                for (int x13 = 0; x13 < c13.Count; x13++)
                                                                                {
                                                                                n13 = c13[x13];

                                                                                if (n2 + n5 + n9 + n13 == 38)
                                                                                {
                                                                                c14 = c13.Select(i => i).ToList();
                                                                                c14.Remove(n13);
                                                                                for (int x14 = 0; x14 < c14.Count; x14++)
                                                                                {
                                                                                n14 = c14[x14];
                                                                                c15 = c14.Select(i => i).ToList();
                                                                                c15.Remove(n14);
                                                                                for (int x15 = 0; x15 < c15.Count; x15++)
                                                                                {
                                                                                n15 = c15[x15];
                                                                                c16 = c15.Select(i => i).ToList();
                                                                                c16.Remove(n15);

                                                                                for (int x16 = 0; x16 < c16.Count; x16++)
                                                                                {
                                                                                n16 = c16[x16];

                                                                                if (n13 + n14 + n15 + n16 == 38)
                                                                                {
                                                                                if (n2 + n6 + n11 + n16 == 38)
                                                                                {
                                                                                c17 = c16.Select(i => i).ToList();
                                                                                c17.Remove(n16);
                                                                                for (int x17 = 0; x17 < c17.Count; x17++)
                                                                                {
                                                                                n17 = c17[x17];

                                                                                if (n3 + n6 + n10 + n14 + n17 == 38)
                                                                                {
                                                                                c18 = c17.Select(i => i).ToList();
                                                                                c18.Remove(n17);
                                                                                for (int x18 = 0; x18 < c18.Count; x18++)
                                                                                {
                                                                                n18 = c18[x18];

                                                                                if (n4 + n9 + n14 + n18 == 38)
                                                                                {
                                                                                if (n7 + n11 + n15 + n18 == 38)
                                                                                {
                                                                                c19 = c18.Select(i => i).ToList();
                                                                                c19.Remove(n18);
                                                                                n19 = c19[0];
                                                                                if(n17 + n18 + n19 == 38)
                                                                                {
                                                                                if(n1 + n5 + n10 + n15 + n19 == 38)
                                                                                {
                                                                                if(n12 + n16 + n19 == 38)
                                                                                {
                                                                                Console.Out.WriteLine("Success");
                                                                                Console.Out.WriteLine(n1);
                                                                                Console.Out.WriteLine(n2);
                                                                                Console.Out.WriteLine(n3);
                                                                                Console.Out.WriteLine(n4);
                                                                                Console.Out.WriteLine(n5);
                                                                                Console.Out.WriteLine(n6);
                                                                                Console.Out.WriteLine(n7);
                                                                                Console.Out.WriteLine(n8);
                                                                                Console.Out.WriteLine(n9);
                                                                                Console.Out.WriteLine(n10);
                                                                                Console.Out.WriteLine(n11);
                                                                                Console.Out.WriteLine(n12);
                                                                                Console.Out.WriteLine(n13);
                                                                                Console.Out.WriteLine(n14);
                                                                                Console.Out.WriteLine(n15);
                                                                                Console.Out.WriteLine(n16);
                                                                                Console.Out.WriteLine(n17);
                                                                                Console.Out.WriteLine(n18);
                                                                                Console.Out.WriteLine(n19);
                                                                                }

                                                                                }
                                                                                }
                                                                                }
                                                                                }
                                                                                }
                                                                                }
                                                                                }
                                                                                }
                                                                                }
                                                                                }
                                                                                }
                                                                                }
                                                                                }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                        }
                    }
                }
            }
            Console.Out.WriteLine(DateTime.Now - time);
            Console.In.Read();
    }

It seems to me that you are simply brute-forcing every possible solution. In actuality, once you have a few (at best, seven) of the numbers solved, the rest of the hexagon can be solved directly, without looping through different possibilities. You then only have to loop through the different possibilities for those seven "squares."

39 ms, 363k recurrence calls. Greetings Lukasz.
Java code:
package game_numbers;

public class Numbers {
    public static int counter=0;

public static byte get_next(byte[] numbers)
    {
    byte elem=0;
    int i=0;
    do
        {
        elem=numbers[i];
        i++;
        }
    while(elem==0 && i<19) ;
    return elem;
    }

// main recur alg

public static boolean findNext(byte[] gameBoard, byte[] numbers)
   {
    boolean found = false;
    byte tmpNumbers[] = copyNumbers(numbers);
    byte elem = get_next(tmpNumbers);

    do
        {
        counter++;
        tmpNumbers = removeFromNumbers(tmpNumbers, elem);
        gameBoard = putOnBoard(gameBoard,elem);
        //printBoard(gameBoard);
        if(match(gameBoard))
            {
            numbers = removeFromNumbers(numbers, elem);
            if(win(numbers))
                found=true;
            else
                {
                found=findNext(gameBoard, numbers);
                if( !found)
                    {
                    gameBoard = removeFromBoard(gameBoard);
                    numbers = addToNumbers(numbers, elem);
                    }
                }
            }
        else
            removeFromBoard(gameBoard);

        elem=get_next(tmpNumbers);
        }
    while (elem!=0 && !found) ;

return found;
}

private static byte[] addToNumbers(byte[] numbers1, byte elem) {
    numbers1[elem-1] = elem;
    return numbers1;
}

private static byte[] copyNumbers(byte[] numbers) {
byte[] newNumbers={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

for(byte i=0; i<19; i++)
    newNumbers[i] = numbers[i];

return newNumbers;
}

private static void printBoard(byte[] gameBoard) {
    System.out.println();
    for(byte temp: gameBoard)
    {
    System.out.print(temp + " ");
    }

}

private static boolean win(byte[] numbers) {

if( get_next(numbers) == 0)
    return true;
else
    return false;
}

private static byte[] removeFromNumbers(byte[] numbers1, byte elem) {
    numbers1[elem-1] = 0;
    return numbers1;
}

private static byte[] removeFromBoard(byte[] gameBoard) {
byte i=0;
while( gameBoard[i] > 0 )
    i++;
gameBoard[i-1] = 0;
return gameBoard;
}

//evaluation function
private static boolean match(byte[] gameBoard) {

byte SUM = 38;

// mapping of permutation to board game

//spiral from outside - quick 300k
byte a=gameBoard[0];
byte b=gameBoard[1];
byte c=gameBoard[2];
byte g=gameBoard[3];
byte l=gameBoard[4];
byte p=gameBoard[5];
byte t=gameBoard[6];
byte s=gameBoard[7];
byte r=gameBoard[8];
byte m=gameBoard[9];
byte h=gameBoard[10];
byte d=gameBoard[11];
byte e=gameBoard[12];
byte f=gameBoard[13];
byte k=gameBoard[14];
byte o=gameBoard[15];
byte n=gameBoard[16];
byte i=gameBoard[17];
byte j=gameBoard[18];

/*     /a|b|c\
      /d|e|f|g\
     /h|i|j|k|l\
      \m|n|o|p/
       \r|s|t/
*/

if( checkVeriables3(a,b,c) == SUM)
    if (checkVeriables4(d,e,f,g) == SUM)
        if (checkVeriables5(h,i,j,k,l) == SUM)
            if (checkVeriables4(m,n,o,p) == SUM)
                if (checkVeriables3(r,s,t) == SUM)
                    if (checkVeriables3(a,d,h) == SUM)
                        if (checkVeriables4(b,e,i,m) == SUM)
                            if (checkVeriables5(c,f,j,n,r) == SUM)
                                if (checkVeriables4(g,k,o,s) == SUM)
                                    if (checkVeriables3(l,p,t) == SUM)
                                        if (checkVeriables3(c,g,l) == SUM)
                                            if (checkVeriables4(b,f,k,p) == SUM)
                                                if (checkVeriables5(a,e,j,o,t) == SUM)
                                                    if (checkVeriables4(d,i,n,s) == SUM)
                                                        if (checkVeriables3(h , m , r) == SUM) return true;
return false;

}

private static byte checkVeriables5(byte h, byte i, byte j, byte k, byte l) {
byte SUM=38;
if (h==0) return SUM;
if (i==0) return SUM;
if (j==0) return SUM;
if (k==0) return SUM;
if (l==0) return SUM;

SUM=(byte)(h+i+j+k+l);

return SUM;
}

private static byte checkVeriables4(byte h, byte i, byte j, byte k) {
    byte SUM=38;
    if (h==0) return SUM;
    if (i==0) return SUM;
    if (j==0) return SUM;
    if (k==0) return SUM;

    SUM=(byte)(h+i+j+k);

    return SUM;
}

private static byte checkVeriables3(byte h, byte i, byte j) {
    byte SUM=38;
    if (h==0) return SUM;
    if (i==0) return SUM;
    if (j==0) return SUM;

    SUM=(byte)(h+i+j);

    return SUM;
}

private static byte[] putOnBoard(byte[] gameBoard, byte elem) {
    byte i=0;
    while( gameBoard[i] > 0 )
        i++;
    gameBoard[i] = elem;
    return gameBoard;

}

public static void main(String[] args)
    {

    byte[] availableNumbers={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
    byte[] gameBoard={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    boolean found = false;
    long time = System.currentTimeMillis();

    while (!found)
        {
        found = findNext(gameBoard,availableNumbers);
        }

    long time1 = System.currentTimeMillis();
    for(byte temp: gameBoard)
        System.out.print(temp + " ");

    System.out.println();
    System.out.println("runing time:" + (time1-time));
    System.out.println("number of recurrence calls:" + counter);
    }
}

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/