text:
Find the best move in a game of Tetris
I like Tetris a lot, but I'm not very good at it. Just once I'd like to see that spaceship take off in front of my own eyes! And since computers are oh-so great at everything, the only possible solution is to make a program to play it for me... except you're going to do that bit for me!
Given a tetromino (shape made of four squares) and a map of the playing field, you are to place the tetromino such that it scores the greatest number of lines (makes the greatest number of rows completely full of blocks) and creates the least number of new holes (an empty space that cannot "see" the top of the playing field1).
Input
The input will contain a character on a single line that represents the dropping tetromino, followed by a 10*18 grid2 of spaces () and plus signs (+).
The character represents any of the seven base tetrominoes found in Tetris. All of the pieces can be rotated by 90 degrees, but not flipped. All the tetrominoes and their rotations are as follows:
         #
S =  ##  ##
    ##    #

          #
Z = ##   ##
     ##  #

    #   ###  ##
L = #   #     #    #
    ##        #  ###

     #  ###  ##
J =  #    #  #     #
    ##       #   ###

          #   #   #
T = ###  ##  ###  ##
     #    #       #

O = ##
    ##

    #
I = #  ####
    #
    #

The grid represents the playing field of Tetris, with + being previously-placed blocks. So, an example input might be the following:
I

+       ++
+    +++++
++ +++++++
++ +++++++
++ +++++++
++ +++++++
++++++ +++

Output
Your output will be identical to the input, but with the tetromino in the ideal position. The tetromino should be represented with # to differentiate them from the pre-placed blocks. In addition to this, you are also to output how many lines/holes your placement creates in the form xL yH on a new line.
The output for the example given above would be the following3:
I

+       ++
+    +++++
++#+++++++
++#+++++++
++#+++++++
++#+++++++
++++++ +++
4L 0H

You are to output only the best result(s); in the case of two or more cases giving the same score, you are to output all of them (separated by a blank line). The best results are to be determined by sorting by the number of lines scored (descending) first, then the number of new holes created (ascending). So, 1L 1H is a better score than 0L 0H.
I will work on creating a list of various inputs and expected output(s) that you can test your program against. Watch this space.
Rules and Disambiguation

This is code-golf, so shortest correct implementation wins.
Input/output may be in any medium that suits your target language (e.g. file, stdin/stdout, text area).
If your target language does not support multiple line input (or it is inconvenient to do so), you may instead delimit each line of the input with commas (,).
You may omit the output of any blank lines in the grid.
Remember that the tetromino falls from above - you may not place the piece "underground". You may therefore assume that all possible placements of the piece will be at "surface-level" (i.e. there are no blocks between the piece and the top of the board).
Assume that there will never be a situation in which you are forced into a game over (the placed tetromino touches the top-center of the field).
Solutions that are identical in output must be omitted (e.g. there are 3 solutions outputs if you naively rotate the O piece).

1 I'm aware that this will create some false positives, but it's a simplification.
2 This is the grid size used in the Game Boy version.
3 Yes, 0H is correct. Check again, I said new holes ;^)

What if a piece would cause 1 new hole, but score 2 lines, vs only scoring 1 line?

Sort by number of lines first. 2 lines > 1 line, so it wins no matter what the number of holes is.

If you free up a hole, does that give you -1H?

Hm, I didn't think of that - it could occur as a result of the naive hole definition. Yes, I guess it would.

In my solution I did not consider freeing up holes. I understood the problem definition in such a way that the existing blocks should not be modified. So no complete lines should be removed and no holes freed up.

C 1009 bytes
#include <stdio.h>
#define L for(n=0;n<18;++n)
int T[19]={54,561,99,306,785,23,547,116,802,71,275,116,39,562,114,305,51,4369,15},W[19]={3,2,3,2,2,3,2,3,2,3,2,3,3,2,3,2,2,1,4},O[7]={0,2,4,8,12,16,17},R[7]={2,2,4,4,4,1,2},G[18],F[24],t=0,I,x,y,S[99],X[99],Y[99],N[99],s,M=0,i,j,k,l,m,n,h,c;char B[99],*C="SZLJTOI";void A(){for(m=0;m<24;++m)F[m]=0;for(m=0;m<4;++m)F[y+m]=(T[I]>>(m*4)&15)<<x;}void D(){S[s]=0;L S[s]+=(G[n]|F[n])==1023;S[s]=200*(S[s])+199;for(m=0;m<10;++m){l=0;L{h=(G[n]|F[n])&1<<m;l|=h;S[s]-=l&&!h;}}}int E(){A();c=0;L c|=G[n]&F[n];return !c;}int main(){S[0]=0;gets(B);while(C[t]!=B[0])++t;I=O[t];L{G[n]=0;gets(B);for(m=0;m<10;++m)G[n]|=(B[m]=='+')?(1<<m):0;}s=0;D();for(i=0;i<R[t];++i){for(x=0;x<10-W[I];x++){y=0;while(E())y++;--y;++s;A();D();if(S[s]>M)M=S[s];X[s]=x;Y[s]=y;N[s]=I;}I++;}for(i=1;i<s;++i)if(S[i]==M){j=i;x=X[i];y=Y[i];I=N[i];A();for(n=1;n<18;++n){for(m=0;m<10;++m)printf((G[n]&1<<m)!=0?"+":((F[n]&1<<m)!=0?"#":" "));printf("\n");}}printf("%dL %dH\n",S[j]/200,S[0]%200-S[j]%200);}

Here is the ungolfed version
#include <stdio.h>

int tiles[19] = {54,561,99,306,785,23,547,116,802,71,275,116,39,562,114,305,51,4369,15};
int widths[19] = {3,2,3,2,2,3,2,3,2,3,2,3,3,2,3,2,2,1,4};
char *codes = "SZLJTOI";
int offsets[7] = {0,2,4,8,12,16,17};
int transformations[7] = {2,2,4,4,4,1,2};
int gameField[18], tileField[24];

int i,j,k,l,m,n,h;
char buffer[99];
int tile=0, tileIndex;
int xpos, ypos;
int scores[99], xplacements[99], yplacements[99], tindex[99];
int scoreIndex, maxScore=0;

void readGame()
{
  gets(buffer);
  while (codes[tile]!=buffer[0]) ++tile;
  tileIndex = offsets[tile];
  for (n=0;n<18;++n)
  {
    gameField[n] = 0;
    gets(buffer);
    for (m=0; m<10;++m)
      gameField[n] |= (buffer[m]=='+')?(1<<m):0;
  }
}

void writeGame()
{
  for (n=1;n<18;++n)
  {
    for (m=0; m<10;++m)
      printf( (tileField[n] & 1<<m) != 0 ? "#" :((gameField[n] & 1<<m) != 0 ? "+" :" "));
    printf("\n");
  }
}

void placeTile()
{
  for (m=0;m<24;++m) tileField[m] = 0;
  for (m=0;m<4;++m)
    tileField[ypos+m] = (tiles[tileIndex]>>(m*4) & 15) << xpos;
}

void score()
{
  scores[scoreIndex] = 0;
  for (n=0;n<18;++n)
    if ((gameField[n] | tileField[n])==1023) scores[scoreIndex]++;

  scores[scoreIndex] = 200*(scores[scoreIndex]) + 199;

  for (m=0;m<10;++m)
  {
    l=0;
    for (n=0;n<18;++n)
    {
      h = (gameField[n] | tileField[n]) & 1<<m;
      l |= h;
      scores[scoreIndex] -= l && !h;
    }
  }
}

int noCollision()
{
  placeTile();
  int coll = 0;
  for (n=0;n<18;++n) coll |= gameField[n] & tileField[n];
  return !coll;
}

int main()
{ scores[0] = 0;
  readGame();
  scoreIndex = 0;
  score();
  for (i=0; i<transformations[tile]; ++i)
  {
    for (xpos=0; xpos<10-widths[tileIndex]; xpos++)
    {
      ypos = 0;
      while (noCollision()) ypos++;
      --ypos;
      ++scoreIndex;
      placeTile();
      score();
      if (scores[scoreIndex]>maxScore) maxScore=scores[scoreIndex];
      xplacements[scoreIndex] = xpos;
      yplacements[scoreIndex] = ypos;
      tindex[scoreIndex] = tileIndex;
    }
    tileIndex++;
  }

  for (i=1;i<scoreIndex; ++i)
    if (scores[i]==maxScore)
    {
      j=i;
      xpos = xplacements[i];
      ypos = yplacements[i];
      tileIndex = tindex[i];
      placeTile();
      writeGame();
    }

  printf("%dL %dH\n", scores[j]/200, scores[0]%200-scores[j]%200);
}

I saw that the main source of lengthy code would probably be the definition of the tiles. So I decided to represent them as bit patterns in a 4x4 bit array. This results in 16 bits that easily fit into a single int. The tiles array holds all the patterns for the 19 possible rotations of the 7 tiles.
When compiling, ignore the warning that gets is deprecated. I know it is but it is the shortest way of reading a line from the input.

At the global scale, you can drop the int as it's assumed.  Several of your printfs only output a single character.  You might be able to replace them with equivalent putchar to save a couple of characters.  For example, changing printf("\n") to putchar(10) :)

puts("") is even shorter if you just want a newline.  Also you can use return!c (no space).  The first time you use an index of a for loop, you can omit the initialisation to 0 as the variables are declared globally.  Also, I think you use the function E only once so it should be possible to just put it inline.

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


text:
Numbers on a Chain
Some positive integers can be shown to have a property called Chain divisibility. For a number to be chain-divisible by n, it must fulfil three requirements:

Each digit divides the number formed by the n  digits that follow it.

For example, the number 7143 is chain-divisible by 2 because 7 divides 14 and 1 divides 43. It is not chain-divisible by 3 because 7 does not divide 143.

Each subsequence taken into account for divisibility must not have leading zeros.

For instance, the number 14208 is not chain-divisible by 2 because 08 has a leading zero. It is, however, chain-divisible by 3, because 208 does not have a leading zero.

All digits in the number must be unique.

For instance, the number 14280 is chain-divisible by 2, 3 and 4. If my explanation of chain divisibility is unclear please ask questions in the comments.
Input
The input to the program consists of a single integer n, followed by a space, then a number that has had certain digits replaced by underscores. For example, the following is a possible input:
3 6__2__4508

n will be greater than 1. The number will never be entirely underscores. You are not guaranteed that the first digit is not an underscore. The first digit will never be 0. n will never be greater or equal to the number of digits in the number.
Output
Output the number, with the digits replaced by integers such that the resulting number is chain-divisible by n. If more than one way of completing the chain-divisible number exists, any may be used as output. If there is no numbers that can complete it, output no answer. For instance, the output of the example input could be:
6132794508

This is code golf, so the shortest code wins.

I assume that if n is greater than or equal to the number of digits in that number, the number is chain divisible?

@Jan Dvorak n will never be equal to or greater than the number of digits in the input. It will always be smaller. I'll edit to reflect that.

Are we required to write a full program, or does a function suffice?

@Martin Yes. Character limit padding.

@Jan Dvorak A full program.

The input rules say the number will have a leading 0. Does that apply for the output as well?

@Dennis The input rules says the number does not have a leading 0. "The first digit will never be 0."

Sorry, forgot a word. The input rules say the number will not have a leading 0. Does that apply for the output as well?

@Dennis Yes, it does. If you think about it a number beginning with a 0 will never be chain divisible anyway, because 0 doesn't divide into anything.

I was rather thinking of dropping the zero, i.e., replacing an underscore at the beginning with either a digit or nothing.

@Dennis You could replace it with a 1, (since 1 divides into anything) but be careful of the third rule for chain divisibility.

Bash+coreutils, 197 bytes
for i in $(eval printf '%s\\n' ${2//_/{0..9\}}|grep -vP '(\d).*\1');{
for((f=d=0;d<${#i}-$1;d++));{
((${i:d+1:1}==0||10#${i:d+1:$1}%${i:d:1}))&&f=
}
[ $f ]&&echo $i&&((c++))
}
((c))||echo no answer

Output:
$ ./chain.sh 3 714_
7140
$ ./chain.sh 2 7141
no answer
$ ./chain.sh 2 14208
no answer
$ ./chain.sh 3 14208
14208
$ ./chain.sh 2 1_208
no answer
$ ./chain.sh 3 1_208
14208
$ ./chain.sh 2 6__2__4508
no answer
$ ./chain.sh 3 6__2__4508
6132794508
$

Explanation

The parameter expansion ${2//_/{0..9\}} replaces all underscores with {0..9}.
The resulting string is evaled to expand all these brace expressions.
The grep weeds out all possibilities where there are any repeated digits.
Then each remaining number is checked, digit-by-digit for conditions 1 and 2.

Python - 239 267
from itertools import*
T=raw_input()
n=int(T[0])
N=len(T)-2
J=''.join
for i in permutations('0123456789',N):
 if all([S in[I,'_']for S,I in zip(T[2:],i)])*all([i[j]>'0'<i[j+1]and int(J(i[j+1:j+n+1]))%int(i[j])<1for j in range(N-n)]):print J(i);exit()
print'no answer'

Slow, but short. Simply compare every possible N-digit permutation with the given pattern and check all requirements. I've tested it only with 7 or 8 digits. Should work for 9 or 10 as well, but will take quite a while.
Edit: I added the missing default output "no answer".

Mathematica Ruby, 349 224 229 bytes
n=$*[0].to_i
r='no answer'
(?0..?9).to_a.permutation($*[1].count'_'){|q|s=$*[1]
q.map{|d|s=s.sub'_',d}
c=s.chars
(t=1
c.each_cons(n+1){|c|e=c.shift.to_i
(t=!t
break)if e<1||c[0]==?0||c.join.to_i%e>0}
(r=s)if t)if c==c.uniq}
$><<r

This is a very naive implementation. I count the number of underscores, and then simply create a list of all digit-permutations of that length, to brute force every possible combination. This will perform horribly for larger numbers of underscores, but this is code golf and not fastest-code. :)
Edit: Ported this from Mathematica. See the edit history for the original version.
Edit: Fixed leading underscore cases.

Shouldn't Permutations be used instead of Tuples (overlooking the character count)?

@DavidCarraher Why? I'd be missing a lot of combinations there, wouldn't I?

Each digit in the number must be unique.  Tuples does not impose that constraint.  Permutations will, provided there are no repeated digits in the input set.  And you can permute only the digits that have not yet been used.  (Although, again, this may lengthen your code.)

@DavidCarraher Ohhh, I overlooked the uniqueness requirement. I need to add that to the inner loop then, in which case I might as well stick with Tuples because it's shorter.

@DavidCarraher fixed.

Java, 421
class C{static int n;public static void main(String[]a){n=new Short(a[0]);f(a[1]);System.out.print("no answer");}static void f(String s){if(s.contains("_"))for(int i=0;i<=9;i++)f(s.replaceFirst("_",i+""));else{for(int i=1;i<s.length()-n+1;){String t=s.substring(i,i+n);if(t.charAt(0)<49||new Long(t)%new Long(s.substring(i-1,i++))>0||s.chars().distinct().count()<s.length())return;}System.out.print(s);System.exit(0);}}}

Less golfed, with explanation:
class C {

    static int n;

    public static void main(String[] a) {
        n = new Short(a[0]);
        f(a[1]);
        System.out.print("no answer");
    }

    /**
     * This method is called recursively, each time with
     * another underscore replaced by a digit, for all possible digits.
     * If there is a solution, the method prints it and exits the program.
     * Otherwise, it returns.
     */
    static void f(String s) {
        if (s.contains("_")) {
            for (int i = 0; i <= 9; i++) {
                f(s.replaceFirst("_", i + ""));
            }
        } else {
            for (int i = 1; i < s.length() - n + 1;) {
                String t = s.substring(i, i + n);       // on each substring...
                if (                                    // test for the three rules
                    t.charAt(0) < 49 ||
                    new Long(t) % new Long(s.substring(i - 1, i++)) > 0 ||
                    s.chars().distinct().count() < s.length()
                ) {
                    return;            // a rule was broken
                }
            }
            System.out.print(s);       // if we made it this far, it's a success!
            System.exit(0);
        }
    }
}

APL (Dyalog Unicode), 179 bytes
d←≠⊆⊢
p←≢¨'|'d'\d'⎕R'|'⊢n←2⊃a←' 'd⍞
⊃(t/⍨t≡¨∪¨t←r/⍨(⍎⊃a)∘{(∧/'0'≠⊃¨x)>1∊×(⊖⍺↓⊖⍎¨⍵)|⍎¨x←1↓⍺,/⍵}¨r←{×≢p:{⍕⍎∊⍉↑('_'d n)(⍵⊆⍨p/⍳≢p)}¨(⊂p/⍕0),⍕¨{⍵~⍳⌊⊃⌽⍵÷10}⍳1-⍨10*+/p⋄⊂n}0),⊂'no answer'

Try it online!
-4 bytes from dzaima.
-9 bytes from ngn.
-4 bytes from Adam.
Golfed by a lot at The APL Orchard.
Explanation
d←≠⊆⊢ splitting function: takes character on left, string on right.
p←≢¨'|'d'\d'⎕R'|'⊢n←2⊃a←' 'd⍞ a multiple assignment:
a←' 'd⍞ a - holds input split on spaces.
n←2⊃ n - holds the number string.
p←≢¨'|'d'\d'⎕R'|'⊢ p - holds the length of each blank space.
Part 1: generating the required number partitions
r←{×≢p:{⍕⍎∊⍉↑('_'d n)(⍵⊆⍨p/⍳≢p)}¨(⊂p/⍕0),⍕¨{⍵~⍳⌊⊃⌽⍵÷10}⍳1-⍨10*+/p⋄⊂n}0
×≢p: ... ⋄⊂n If there are no underscores, return the number, wrapped.
Otherwise:
⍳1-⍨10*+/p generate range 1..(9 repeated sum(p) times)
{⍵~⍳⌊⊃⌽⍵÷10} remove 1..10^(sum(p)-1), getting all sum(p) digit numbers.
⍕¨ convert each to string
(⊂p/⍕0), prepend 0 repeated sum(p) times to it
{⍕⍎∊⍉↑('_'d n)(⍵⊆⍨p/⍳≢p)}¨  execute the following for each no. string:
(⍵⊆⍨p/⍳≢p) split into pieces of sizes in p
↑('_'d n) add the input to it and make a 2xn matrix
⍕⍎∊⍉ transpose the fillers and enlist them, then remove all spaces using ⍕⍎
r/⍨ filter this list by:
Part 2: checking chain divisibility
(⍎⊃a)∘{(∧/'0'≠⊃¨x)>1∊×(⊖⍺↓⊖⍎¨⍵)|⍎¨x←1↓⍺,/⍵}¨
(⍎⊃a)∘{...} execute the following, using the first number as constant left argument:
⍎¨x←1↓⍺,/⍵ store overlapping groups of 3 in x, convert to int
| modulo:
(⊖⍺↓⊖⍎¨⍵) list of numbers they should be divisible by
1∊× are any of them truthy?
> check if the result is lesser than:
(∧/'0'≠⊃¨x) whether any of the groups have a leading zero
filter complete!
Part 3: checking uniqueness
t≡¨∪¨t← boolean mask for whether each number matches itself uniquified.
t/⍨ filter to get the final array
⊃(...),⊂'no answer' pick the first item of the result with 'no answer' appended.
if there are no results, it will default to that.

source: Stack Exchange

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

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

sort: votes


text:
Produce a Simple Station Model
A station model is a diagram for recording the weather at a certain place and time.
Challenge
You must write the shortest code possible to graphically output a simplified (explained later) station model.

Ticks
A tick is a line on the wind barb. A 50 knot tick is a triangle. A 10 knot tick is a line. A 5 knot tick is half the length of a 10 knot tick. The windspeed is indicated by summing the ticks, using the largest value symbols whenever possible. The ticks start at the end of the line and are arranged in descending order of size toward the circle. An exception is 5 knots, where the tick is placed a short distance away from the end (to avoid ambiguity with 10 knots.)
Here is some pseudocode to calculate the ticks required
set f=int(s/5)
set t=int(f/2)
f=f-(t*2)
set ft = int(t/5)
t=t-(ft*5)

Where f is the number of 5 knot ticks, t is the number of 10 knot ticks and ft is the number od 50 knot ticks. (This rounds down to the nearest 5, but your code should round up or down, whichever is nearer.) Note that there is only ever one 5 knot tick.
Other
You may only display two things on your station model: wind speed and direction. These must be supplied by the user: hardcoding is not permitted. The wind speed must be a positive integer in knots while the wind direction must be in letters (e.g. NNE, W, ESE). 16 points of the compass will be considered (up to three letters.) See http://en.wikipedia.org/wiki/Points_of_the_compass
The 50 knots tick must be as in the picture above.
Set cloud cover to clear (the circle must be empty.)
The highest wind speed allowed is 201 knots (round it to 200).
Since the wind ticks only increase in imcrements of 5, round all wind speeds to the nearest 5.
As always, since this is code golf, the shortest code wins.
Examples
All of the following have a cloud cover of clear.

20 knots, SW (225°)

15 knots, N (0°)
Test cases
50 knots, NNE
0 knots
12 knots S
112 knots WNW

What's the maximum wind speed we need to support?

@Martin Well the fastest ever wind was 201 knots so go with that

The sample diagram you provide contains about 18 items of data. You've specified input for 2 of them. That leaves a massive hole in the spec. And then the level of detail in the output spec ("either graphically or using ascii") also leaves a massive hole, pretty much the entire thing. There's no point in a code golf question where people aren't trying to golf the same mapping from input to output: it becomes about arguing over formatting rather than about writing clever code.

@PeterTaylor I think "You must use two variables: wind speed and direction." is intended to mean that only this subset of the larger diagram is to be represented.

This could be a fun question, but it needs more details and examples.

@MartinBüttner, in that case the question shouldn't say "write the shortest code possible to output a station model", and it probably shouldn't have the image of a station model at all. It seems designed to confuse.

@PeterTaylor I can agree with that. Beta Decay, I don't think your new examples add a lot. Now there's a question if the far side of the 50-knots triangle has to be perpendicular to the stem or not. Also, what would be interesting is an example for more than 100 knots. And what does "Set cloud cover to overcast." mean? I suppose it's referring to the central circle thing, but which pattern stands for overcast? Lastly, I don't see the point of having test cases without reference solutions.

is it ASCII or not? ASCII is easier but only if significant compromise on the appearance is allowed. Define thoroughly or eliminate. 2. Although not clear from the question, the internet reveals that for wind speeds of 100 and above multiple triangles worth 50 each are used. Symbols (triangles, ticks, half ticks) start at the far end of the arrow and work in descending size towards the centre circle (except at 5knots). 3. It seems only 16 compass points are required? (no need to support 32 or higher.) 4.Does overcast mean full circle or empty circle? (only the latter works for ASCII art.)

@steveverrill I changed overcast to clear, so it is now an empty circle. I'll change it to purely graphical however.

@BetaDecay I've clarified that the answer should round to the nearest 5, not round down. Also, compass points SEE and NWW do not exist (or at least are not standard.) A 3-letter compass point is made by combining a 1-letter and a 2-letter (in that order.) I don't think we've had a question about parsing compass points before, but we've had the inverse, twice: http://codegolf.stackexchange.com/q/21927/15599 http://codegolf.stackexchange.com/q/17438/15599

@steveverill Hey, thanks for all of that

BBC BASIC, 273 ASCII characters (not golfed yet)
Emulator at http://www.bbcbasic.co.uk/bbcwin/bbcwin.html
Parsing the direction is a dirty hack. I simply take a walk through a cartesian grid for each letter input. They aren´t echoed to the screen, and the input is terminated when a space is received.
As this is codegolf, I don't bother to normalise the direction vector. Therefore the size of the symbol drawn is dependent on the number of characters input. The proportions are the same for all inputs, however. Also, for the 3-letter inputs the angle is 4 degrees closer to the diagonal than it should be. For example, NNE is atan(0.5)=26.57 degrees instead of the correct 22.5 degrees, but it is barely noticeable. Both these points could be corrected for about 20-30 characters.
After the direction, the speed is input (this is echoed to the screen and terminated with a newline.)
  x=0
  y=0
  REPEAT
    d=GET                             :REM get character from keyboard
    x+=(d=87)-(d=69)                  :REM d=87 evaluates to -1 if "W", d=69 is -1 if "E"
    y+=(d=83)-(d=78)                  :REM d=83 evaluates to -1 if "S", d=69 is -1 if "N"
  UNTILd=32
  x*=20                               :REM boost the sizes of x and y
  y*=20                               :REM normalization code would go here
  INPUTs
  s=INT(s/5+.5)                       :REM divide s by 5 and round to nearest int. 50-tick=10, 10-tick=2, 5-tick=1
  MOVE600,500                         :REM move to centre of circle
  PLOT145,x,y                         :REM draw circle centred at 600,500 with 600+x,500+y on its edge. cursor remains at the latter position.
  IFs=0END                            :REM exit if wind=0
  DRAWBY 9*x,9*y                      :REM draw the shaft of the arrow, 9 units long, from current position
  IFs>1 MOVEBY x,y                    :REM if rounded windspeed >5 move one more space out.
  WHILEs>1                            :REM while there are still 50-ticks and 10-ticks to draw
    MOVEBY 2*y,-2*x                   :REM move 2 units clockwise of the shaft
    PLOT1-(s>9)*80,-2*y-x,2*x-y       :REM draw a diagonal line back to the shaft. If s is 10 or over, plot mode 81 will take the last 2 positions of the graphics cursor and draw a triangle.
    s-=2-(s>9)*8                      :REM Decrement s by 2 or 10, according to the last barb drawn.
  ENDWHILE
  IFs MOVEBY -x,-y:DRAWBY x/2+y,y/2-x :REM If s=1 draw the 5-tick. Unlike the other ticks, it is drawn from its root outwards.

Output
All the test cases from the quesion are shown, plus two more to illustrate 2-letter directions:
50 knots, NNE
0 knots
12 knots S
112 knots WNW
195 knots SE
5 knots SW

In order to show them all together, I didn't clear the screen between runs. The different sizes (but constant proportions) of the arrows can be seen.

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


text:
Find a criminal from his ear, finger, and head
Prior to the discovery of fingerprints and DNA testing, the British police used an anthropometric system to identify repeat offenders. Certain parts of the bodies of criminals were measured and stored in records -- these parts of the body were assumed to not change in size after adulthood. This system was known as bertillonnage.
The diagram below shows a filing system used by the police to access these records quickly.

Diagram 1: A filing system with numbered drawers.
Note: if you cannot see the image, try the imgur mirror  or compile it yourself.
The filing cabinet consists of 81 numbered drawers. Each drawer contains cards, and each card has measurements of particular parts of a criminal's body:

The length of their head (H)
The breadth of their head (B)
The width of their right ear (E)
The length of their index finger (F)

Each measurement is classified as either small, medium or large.
For example, drawer 56 contains cards with the following characteristics: small H, large B, medium E, and small F. This can be notated using the letters S, M, and L in place of small, medium, and large:
SH,LB,ME,SF

Note that the size letter goes first, then what the measurement is. In addition, an exclamation point ! may be placed in front to cause a negative:
!SH,LB,!ME,SF

This indicates cards that have the following characteristics: not small H, large B, not medium E, and small F. There are four drawers that contain cards with these characteristics -- 58, 60, 61, and 63.
Your task is to write a program, that, when given a string notating some characteristics, outputs all of the drawers that contain cards with those characteristics. If there are no drawers that contain cards with the given characteristics, output 0.
Here are some sample inputs and outputs.

Input: SH,LB,ME,SF
Output: 56
Input: !SH,LB,!ME,SF
Output: 58,60,61,63
Input: SB,!MF,!LF
Output: 1,2,3,4,5,6,7,8,9
Input: MH,!MH
Output: 0

This is code golf, so the shortest entry wins. Ask questions in the comments if the specification is not clear.

As a historical note for accuracy, bertillonnage systems were actually much more complicated than this simplified version, using 9 measurements instead of 4, and thus using a more involved filing system than the one depicted here.

Oh no! not ANOTHER Sudoku question ;-)

@steveverrill I actually made the diagram from a sudoku template, so there's some truth in that :o

GolfScript 95 (DEMO)
','/:r;81,{r{1$[[.9%3/\.3%\.27/\9/3%]{'SML'=}%'HEBF']zip{''+}%\.,3=\1${(;}*@?)!!=},!\;},{)}%0or

Ruby 1.9.3 - 173 157 143
x=(1..81).select{|j|$*[0].split(?,).all?{|y|i=j-1
z='SML'
[z[i%9/3]+?H,z[i%3]+?E,z[i/27]+?B,z[i/9%3]+?F].member?(y[-2,2])^y[?!]}}
p x==[]?[0]:x

Edit:

applied Three If By Whiskey's tips.
taken parameters from the command line to save some more chars

Online demo: http://ideone.com/lodTLt

select is a shorter synonym for find_all. You could trim another two characters by replacing y[-2..-1] with y[-2,2], and three more still by using ==[] instead of .empty?.

@ThreeIfByWhiskey Great tips, thanks! I've edited my answer.

Scala - 951
Definitely won't win this one, mainly due to the names of built in functions I think.
def m(a: List[Int]) = 0 to 8 flatMap (x => a map (_ + 9*x)) toSet
var SH = m(List(1,2,3))
var MH = m(List(4,5,6))
var LH = m(List(7,8,9))
var SE = m(List(1,4,7))
var ME = m(List(2,5,8))
var LE = m(List(3,6,9))
var SB = 1 to 27 toSet
var MB = 28 to 54 toSet
var LB = 55 to 81 toSet
def l(a: List[Int]) = 0 to 2 flatMap (x => a map (_+27*x)) toSet
var SF = l(1 to 9 toList)
var MF = l(10 to 18 toList)
var LF = l(19 to 27 toList)

var j = Map(("LH",LH),("MH",MH),("SH",SH),("LB",LB),("MB",MB),("SB",SB),("LF",LF),("MF",MF),("SF",SF),("LE",LE),("ME",ME),("SE",SE))

def f(x : String) = {
  def h(i : List[String], k : Set[Int]) : Set[Int] = {
      if(i isEmpty) k
      else if(i.head.startsWith("!")) h(i.tail, k filterNot (j(i.head.replace("!","")) contains _))
      else h(i.tail, k intersect j(i.head))
  }
  h(x split "," toList, 1 to 81 toSet) mkString ","
}

Argument is passed into the function f
f("SH,LB,ME,SF") = 56

T-SQL - 547 544
Not a winning entry, but suited to this type of problem.
Grid Table Setup - 254
SELECT ROW_NUMBER()OVER(ORDER BY (SELECT $))I,LEFT(Z,1)E,RIGHT(Z,1)H,LEFT(Y,1)F,RIGHT(Y,1)B INTO G FROM(VALUES('SS'),('MS'),('LS'),('SM'),('MM'),('LM'),('SL'),('ML'),('LL'))FB(Y),(VALUES('SS'),('MS'),('LS'),('SM'),('MM'),('LM'),('SL'),('ML'),('LL'))EH(Z)

Query - 293 290
DECLARE @S CHAR(400)='SELECT ISNULL(SUBSTRING(O,2,99),0)FROM (SELECT CONCAT('','',I)FROM G WHERE '+REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REVERSE(@i),',',' AND '),'S!','!S'),'M!','!M'),'L!','!L'),'S','=''S'''),'M','=''M'''),'L','=''L''')+' FOR XML PATH(''''))O(O)';EXEC(@S)

Input is done by declaring @i before the query
DECLARE @I VARCHAR(50) = 'SB,!MF,!LF';

I could save a further 89 characters if the output doesn't have to be comma delimited row
DECLARE @S CHAR(400)='SELECT I FROM G WHERE '+REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REVERSE(@i),',',' AND '),'S!','!S'),'M!','!M'),'L!','!L'),'S','=''S'''),'M','=''M'''),'L','=''L''')

Mathematica 191 235
Represents each cell number in base 3. Each digit position represents a bodily feature.  The value of the digit, {0,1,2}, represents "Small","Medium","Large", respectively.
The features correspond to the digits as follows:

{"breadthOfHead", "IndexFingerLength", "LengthOfHead", "WidthOfRightEar"}

For example, the input,
{"SH","LB","ME","SF"}

signifies:

"LB" implies breadthOfHead = 2 (large)
"SF" implies IndexFingerLength  = 0 (small)
"SH" implies LengthOfHead = 0 (small)
"ME" implies WidthOfRightEar = 1 (medium)

2001in base 3 is 55 in base 10.
We need to add one because we are counting cells from 1, not zero.

Code
c=Characters;t=Table[IntegerDigits[k,3,4],{k,0,80}];
f@i_:=1+FromDigits[#,3]&/@Intersection@@(Cases[t,#]&/@(ReplacePart[{_,_,_,_},{#}]&/@(c/@i
/.Thread[c@"BFHESML"-> {1,2,3,4,0,1,2}]/.{{"!",v_,n_}:> (n-> Except[v]),{v_Integer,n_}:> n-> v})))
/.{}:>0

Test Cases
f[{"SH","LB","ME","SF"}]

{56}

f[{"!SH","LB","!ME","SF"}]

{58, 60, 61, 63}

f[{"SB","!MF","!LF"}]

{1, 2, 3, 4, 5, 6, 7, 8, 9}

f[{"MH","!MH"}]

0

Python 2 - 194
from itertools import*
n=map(set,['012']*4)
for x in raw_input().split(','):n['BFHE'.find(x[-1])]&=set(`'SML'.find(x[-2])`)^set('012'*(x<'"'))
print[1+int(''.join(x),3)for x in product(*n)]or[0]

Output has brackets, and don't care about order of output
Some suggestions from Falko, and a couple from myself to take off 10 chars.

Yes, it's okay to have the input wrapped in brackets.

Do they need to be in order?

Good question. Actually, the output doesn't have to be in order - although I'm not sure how outputting them in a different order would save characters.

I'm using python set()s, converting them back to lists, getting the product, converting to base 3 numbers back to ints.  In all that, the order gets a little jumbled and I need to use sorted() if I want them back in the right order.

I see. Order isn't important so the sorted() may be removed. Nice solution.

Nice solution! With from itertools import* you can save a byte and with `` rather than str 3 more. And comparing x[0]<'"' is shorter than x[0]=='!'. :)

Python 3 - 192 - Try it!
from itertools import*
S=input().split(',')
print([i+1for i in range(81)if eval('*'.join('(list(product(*["SML"]*4))[i][%d]%s="%s")'%('BFHE'.find(s[-1]),'!='[s[0]>'!'],s[-2])for s in S))]or 0)


text:
ASCII Art Code Generator
I have a program that generates formatted Brainfuck code. I run my program
./example "S"

and the output is
 +[>+
<
 +++
    ]
>--.

which prints S in Brainfuck.
Your objective is to write a program which accepts a string as input and outputs source code in another language which prints that string.

The source code your program outputs must be formatted in such a way that it represents the string in ASCII art (printed horizontally, not vertically).
The source code cannot contain the string (it may, however, contain letters that occur in the string, just not sequentially)

Otherwise,

Standard loopholes apply.
Shortest code wins.

Please title your submission with the language it is written in, the language it outputs, and the total size in bytes. Please include the output of your program when you enter the string UNCOPYRIGHTABLE.
Thanks!

Does the program have to handle all printable ASCII characters or just uppercase letters? What about white space?

@squeamishossifrage Just uppercase letters. Whitespace is preferable, but I realize the string " " might be impossible to represent, so its optional.

C --> Brainfuck 556 Bytes
Excluding unnecessary whitespace. I could easily save another hundred by changing the font data in d[]from hex to a string in quotemarks.
i,j,s,t,u,v,w,h;
char a[99],b[9999],k,d[]={0x6F,0x3B,0x5A,0xD5,0x7A,0x6A,0x5B,0x2F,0xD0,0x57,0xA1,0x1B,0xCF,0x4F,0x5F,0x6E,0x6D,0x4E,0x79,0x3A,0x1F,0x95,0x9F,0xA6,0x3D,0x76};
f(int z){
  return d[a[j-1-t%(2*w*j)/w/2]-65]>>z&1?z=b[i*v/u],b[i++*v/u]=' ',z:' ';
}

main(){
  for(scanf("%s",a);a[j];i++)a[j]-k?k++,b[i]='+':(b[i]='.',t+=(0xE7572B70967DB>>(a[j]*2-130)&3)+5,j++);

  s=i/t+2;
  u=t*(s-1);
  v=i;
  i=0;

  w=2*s;h=2*s+1;
  for(t=2*w*h*j;t--;)putchar(
    t%(2*w*j)?
      t/2/w/j%s?

        t%s||!(t/4%s)?' ':f(t/s%4/2+t/2/w/j/s*2|7*(t/s%4==2))
      :(
        (t%s)&&(t/s+1&2)?f(4+t/2/w/j/s):' '
      )
    :10  //newline
  );

}

This uses a calculator font (for low entropy, only one byte per letter) and a very naive Brainfuck compiler inspired by https://codegolf.stackexchange.com/a/35801/15599 (except I use plus instead of minus.) The first for loop compiles the text in a to the string b, and also calculates the number of strokes required to draw the formatted code, using the 13-digit hex magic number (all characters are 5-8 strokes.)
Given the total program length and the stroke count, the number of characters per stroke is calculated (this can be very small if the characters are the same or in ascending order, and very large if the characters are in descending order.)
Most of the rest of the program is dedicated to deciding whether whitespace or one of the strokes needs to be printed. If the cursor is over a stroke square, the function fis called with the number of that stroke as an argument. It returns a space if that stroke is not required for the current letter, or a character from the program if it is. Because the number of characters required to complete the ASCII art may be more than the characters in the program, occasionally a space is inserted, hence the calculation b[i * v/u].
There are four single strokes and four double strokes in the font, numbered as follows, which are either present or absent, depending on the letter.
 6666 6666
3    7    2
3    7    2
3    7    2
3    7    2
 5555 5555
1    7    0
1    7    0
1    7    0
1    7    0
 4444 4444

Output
Test at http://copy.sh/brainfuck/
ABC
 + ++ +++                                ++++ + ++
+         +         +
+         +         +                   +
+                   +                   +
+         +         +
 ++++ + ++           +++  ++++
+                   +         +         +
+         +                   +         +
+         +         +                   +
+         +         +         +
                     ++++ + ++           ++.  +.+.

DEF
 + ++ ++ +           ++++  +++           ++ + ++++
          +         +                   +
     +    +                             +
     +    +         +                   +
          +         +                   +
                     ++ + +++            ++++ + ++
     +    +         +
     +    +         +                   +
     +              +                   +
     +    +         +
 ++++ + ++           ++.  +.+.

GHIJK
 + + +++                         ++  +++         +++  ++
+               +       +           +                               +
+               +       +           +                   +
+               +       +           +                   +           +
                  ++ +++                                         + + +++
+       +       +                   +           +       +           +   +
+               +       +           +           +       +           +
+       +       +       +           +           +                   +   +
 +++ + +                         ++. +.          +.+ .+.

LMNOP
                 + + +++         + + +++         + + +++         + + +++
+                   +   +       +       +       +               +       +
+               +   +           +       +       +       +       +
+               +   +   +       +               +       +       +       +
                                                                 + + +++
+               +   +   +       +       +               +       +
+       +       +       +       +       +       +       +
+       +       +   +   +               +       +       +       +
 + . +.+                                         . + .+.

QRSTU
 + + +++         +++ +++         +++ ++
+       +       +       +       +               +               +       +
+       +       +       +       +               +               +
+       +       +       +       +               +               +       +
 +++ +++                         + + +++         +++ +++
        +       +                       +       +               +
        +       +                       +       +               +       +
        +       +                       +       +               +       +
                                 +++  ++         +++ .+.         +.+ .+.

VWXYZ
                                                                + + +++
   +   +       +   +   +               +       +       +               +
   +   +       +   +   +           +           +       +               +
   +   +       +   +   +           +           +       +               +
                                +++ +++         + + +++         +++ ++
   +   +       +   +   +       +   +                   +       +
   +           +   +   +       +   +                   +       +
   +   +           +   +       +   +                   +       +
+++ + +         +++ +++                         ++  .+.         +.+ .+.

COPYABLE
with most strings with letters in random order (not ascending) the letter size is much larger, and the letters look much better. Unfortunately the file sizes get quite large. I cannot upload the full word UCOPYRIGHTABLE here, COPYABLE is about the longest word I am allowed.
        + +++++++++ +++++++++++                         + +++++++++ +++++++++++                         ++ ++++++++ +++++++++++                                                                         +++ +.+++++ +++++++.+.+                                                                                ++++ ++++.+ +++++++++++
       +                                               +                       +                       +                       +                                               +                       +                       +                       +                                               +                                               +
       +                                               +                       +                       +                       +                       +                       +                       +                       +                       +                                               +                                               +
       +                                               +                       +                                               +                       +                       +                       +                       +                       +                                               +                                               +
       +                                               +                       +                       +                       +                       +                       +                       +                       +                       +                                               +                                               +
       +                                               +                                               +                       +                       +                       +                       +                       +                       +                                               +                                               +
       +                                               +                       +                       +                       +                       +                       +                       +                       +                       +                                               +                                               +
       +                                                                       +                       +                       +                       +                       +                       +                       +                       +                                               +                                               +
       +                                               +                       +                       +                       +                       +                       +                       +                       +                       +                                               +                                               +
                                                       +                       +                       +                       +                       +                       +                       +                       +                       +                                               +                                               +
       +                                               +                       +                       +                       +                       +                       +                       +                       +                       +                                               +
       +                                               +                       +                       +                       +                       +                       +                       +                       +                       +                                               +                                               +
                                                                                +++++++++ + +++++++++++                         ++++++++++  +++++++++++                         +++++++++++  ++++++++++                         +++++++++++ + +++++++++                                                                         ++++++++++. +. ++++++++
       +                                               +                       .                       +                                                                       +                       +                       +                       +                       +                       +                       +                       +
       +                                               +                                               +                                                                       +                       +                       +                       +                       +                       +                       +                       +
       +                                               +                       +                       +                                                                       +                       +                       +                       +                       +                       +                       +                       +
                                                       +                       +                       +                                                                       +                       +                       +                       +                       +                       +                       +                       +
       +                                               +                       +                       +                                                                       +                       +                       +                       +                       +                       +                       +
       +                                               +                       +                       +                                                                       +                       +                       +                       +                       +                       +                       +                       +
       +                                               +                       +                       +                                                                       +                       +                       +                       +                       +                       +                                               +
       +                                               +                       +                       +                                                                       +                       +                       +                       +                       +                       +                       +                       +
       +                                               +                       +                       +                                                                       +                       +                       +                       +                       +                                               +                       +
       +                                               +                       +                       +                                                                       +                       +                       +                       +                       +                       +                       +                       +
       +                                               +                       +                       +                                                                       +                       +                       +                       +                                               +                       +                       +
        +++++++++++ +++++++ +++                         +++++++++++ ++++++++ ++                                                                         +++++++++++ +++++++++ +                                                                         +++++++++++ ++++++++++                          +++++++++++ +++++++++++                          ++++++++++ ++++++++++.

Perl → Befunge, 868 bytes
OK, I'll get the ball rolling. This could be golfed down a bit more, but my head is starting to hurt...
$_=" f,j f,jjj f,lgdlH,b >llb ,l,b lb ,lb , f,j f j f >>l>,lb ,9vb >lb,Hlb,H>vb >999*+,
mg8Hg8Ha8c8g8Hgb8Hab8,8k/ 8Ha8Hi /H8HgH8g8k >H9ghgH9b 'bhbhgH9ghg9+gH9ga//
ma8Hg8Ha8c8ahgbhabhh /bhah VdhibHH9ghb >H9ghgH9abhbhgH*g9+g ii /b>l,^b //
>H^>>Hned*angne ned* eneknabnn<b nangn idH*gned*gneb*>>,b *kngH5g*6 Adb><aha//b
H*g2HgH3a4Hg5Ha6c7gHHgb1Hab2+3H ib4Ha5Hg6kiHH7g8c, id1H iabHk3k4+g >+ ,^>^dd 7/ ib *k //b
+1g+HgH+g+Hg+Ha+c+g,Hgb+kk >^+ki +Ha+Hg+HgH+g+cki'+ki ,gk+k>^gbHc^H 9*gb8+b//a
^<b ^>^ebe^'>^e >^e>>^a >^>> >^gd>^ke> >^b '>^e>>^g>^g e^ >^a >^~'i>^b i >2+^b >^b e>gHaV V >^gb>^bHHHHHH";
s/n/*H/g;s/m/H8g8HgH8/g;s/l/v>/g;s/k/Hb/g;s/j/f>,/g;s/i/\\/g;s/h/9H/g;s/g/bd/g;s/f/ve/g;s/e/>>>/g;s/d/ H/g;s/c/HaH/g;s/b/  /g;s/a/    /g;@f=split$/;
@s=split('',$ARGV[0]);foreach$r(0..6){for($i=0;$i<@s;$i++){print substr($f[$r],(ord($s[$i])-65)*6,6).$"}print$r?'':' @',$/}

Examples:
The shorter examples can be copy-pasted into online interpreters like this one, but UNCOPYRIGHTABLE appears to result in a program that is too long for all the online interpreters to handle.
$ perl bf.pl ABCDEFGHI
 v>>>, v>>>>,  v>>>, v>>>>, v>>>>, v>>>>,  v>>>, v>   H  Hv>H,  @
H8   H 8H   H H8   H 8H   H 8H     8H     H8   H 8H   H   8H
H8   H 8H   H H8     8H   H 8H     8H     H8     9H   H   9H
>H^>>H *H>>>  H*     *H   H *H>>>  *H>>>  H* >>> *H>>>H   *H
H*   H 2H   H H3     4H   H 5H     6H     H7   H HH   H   1H
+1   H +H   H H+   H +H   H +H     +H     H+   H ,H   H   +H
^<   ^ >^>>>   >>>^' >^>>>  >^>>>> >^      >^>>  >^   H  H>^H

$ perl bf.pl JKLMNOPQR
   >v> v>   , v>,    v>   , v>   ,  v>>>, v>>>>,  v>>>  v>>>>,  @
    8, 8H  /  8H     8H\ /H 8H   H H8   H 8H   > H9   H 9H   H
    9H 9H /   9H     9H V H 9H\  H H9   H 9H   > H9   H 9H   H
    *H *H<    *H     *H   H *H \ H H*   H *H>>>  H*   H *H>>>
    2+ 3H \   4H     5H   H 6H  \H H7   H 8H     H, \ H 1H \
H   >^ +H  \  +H     +H   H +H   H H+   H +H     HH  \' +H  \
 >>>>  >^   ' >^>>>> >^   H >^   H  >>>^  >^      >^~'\ >^   \

$ perl bf.pl STUVWXYZ
 v>>>  >>v>>, v>   , 9v   > v>  ,H v>  ,H >v   > 999*+,  @
H9   '   9H   9H   H H9   H 9H   H 9+   H H9   H     //
H9       9H   9H   H H*   H 9+   H  \\ /   >v>,^    //
 *>>,    *H   *H   H H5   H *6 A H   ><     9H     //
    HH   3H   4+   H  >+ ,^ >^ H H  7/ \    *H    //
,   HH   +H   >^   H   HH     H^H  9*   H   8+   //
 >2+^    >^    >>>>    HH     V V  >^   H   >^   HHHHHH

$ perl bf.pl UNCOPYRIGHTABLE
v>   , v>   ,  v>>>,  v>>>, v>>>>, >v   > v>>>>,  Hv>H,  v>>>, v>   H >>v>>,  v>>>, v>>>>, v>,    v>>>>,  @
9H   H 8H   H H8   H H8   H 8H   > H9   H 9H   H   8H   H8   H 8H   H   9H   H8   H 8H   H 8H     8H
9H   H 9H\  H H8     H9   H 9H   >  >v>,^ 9H   H   9H   H8     9H   H   9H   H8   H 8H   H 9H     8H
*H   H *H \ H H*     H*   H *H>>>    9H   *H>>>    *H   H* >>> *H>>>H   *H   >H^>>H *H>>>  *H     *H>>>
4+   H 6H  \H H3     H7   H 8H       *H   1H \     1H   H7   H HH   H   3H   H*   H 2H   H 4H     5H
>^   H +H   H H+   H H+   H +H       8+   +H  \    +H   H+   H ,H   H   +H   +1   H +H   H +H     +H
 >>>>  >^   H  >>>^'  >>>^  >^       >^   >^   \  H>^H   >^>>  >^   H   >^   ^<   ^ >^>>>  >^>>>> >^>>>>

Note:
The @ character at the end of the first line of output tells Befunge to stop running. Without it, the program would keep repeating the same word forever.

I like the ASCII font :)

C → Brainfuck, 855 bytes
Some newlines added to improve readability. Notice it segfaults on lowercase letters and symbols. Test the output here.
#define p putchar
#define V(x) c=v[1][x]-65;
l[]={96,48,24,12,66,98,60,90,6,70,102,54,118,14,62,126},e[]={2863659686,
3937331886,1787332774,3937053358,4170115215,2291067023,1789692070,2863659690,
1646404134,1778384896,2864569258,4169697416,1145534458,1165457300,1789569702,
2291051182,1823124134,2863573678,1778804902,572662319,1789569706,648719018,
2943841348,2863033002,572680874,4164034831},a[]={36,36,24,34,30,26,29,36,20,20,
30,20,28,26,32,28,33,34,28,20,32,30,28,32,24,24},r,o,j,k,c,z;char*b[]={
"-[+>+<[+<]>]>+","-[+[>---<<]>+]>-","+[>+<+++++++]>",">+++[[-<]>>--]<",
"+[>+<+++]>----","+[>+<+++]>","-[+[+<]>>+]<+"};main(i,v)char**v;{for(;r<8;r++){
for(i=0;v[1][i];i++)for(o=0;o<8;o++){V(i)if((l[(e[c]>>(4*r))&15]>>o)&1){V(j)
if(k==a[c]){j++;k=0;}V(j)z=k-strlen(b[c/4]);if(z<0)p(b[c/4][k]);else{c=(c%4)-z;
!c?p(46):(c>0?p(43):p(62));}k++;}else p(32);}p(10);}}

Examples
It looks a lot nicer on a terminal :(
$ ./art ABCDEFGHI

  -[+>   +<[+<    ]>]>   +.>>>   >>>>>>  >>>>>>   >>>>   >>  -[   +>+<
 [+  <]  >]  >+  +.  >>  >>  >>  >>      >>      >>  >>  >>  >>    >>
 -[  +>  +<  [+  <]      >]  >+  ++      .>      >>      >>  >>    -[
 +>+<[+  <]>]>   ++      ++  .>  >>>>>   >>>>>   >>      >>>-[+    [>
 ---<<]  >+]>-   .>      >>  >>  >>>>>   >>>-[   +[ >--  -<<]>+    ]>
 -+  .>  >>  >>  >>      >-  [+  [>      --      -<  <]  >+  ]>    -+
 +.  >>  >>  >>  >>  >>  -[  +[  >-      --      <<  ]>  +]  >-    ++
 +.  >>  >>>>>    >>>>   >>>>>   +[>+<+  ++       ++++   ]>  .>   >>>>

 $ ./art JKLMNOPQR

     +[  >+  <+  ++      ++  ++  ]    >   +.>>   >>+[>    +<++   +++++
     ]>  ++  .>  >>      >>>>>>  >>   >  >+  [>  +<  ++  ++  ++  +]  >+
     ++  .> >>   ++      + [[ -  < ]> >  --  ]<  .>  >>  >>  >>  >>  >>
     >>  +++     [[      - <] >  > -- ]  <+  .>  >>  >>  >>  >>  >+  ++
     [[  -<]     >>      - -] <  + +. >  >>  >>  >>>>>   >>  >>  >+++[
     [-  <] >>   --      ]    <  + ++ .  >>  >>  >>      >>  >+  [>  +<
 ++  +]  >-  --  -.      >    >  >   >>  >>  >>  >>      >> >>>  >>  +[
  >+<+   ++  ]>  ----+.  >    >  >    >   >>>>   >>       >>>>   >>  >>

$ ./art STUVWXYZ

  +[>+   <+++]>  --  --  ++  .>  >    >  >>  >>  >>  >>  +[>+<+
 ++  ]>    --    --  ++  +.  >>  +    [  >+  <+  ++  ]>      .>
 >>        >>    >>  >>  >>  >>  >    >  >>  >>  >>  +[     >+
  <+++     ]>    +.  >>  >>  >>  > >> >   >>>>    >>>>     +[
  >+<+     ++    ]>  ++  .>  >>  > >> >   >>>>     >>      >>
     +[    >+    <+  ++  ]>  ++  + .> >  >>  >>    >>     >>
 >>  >>    >>    >>  -[   +[+<   ]>>+]<  +.  >>    >>    >>
  >>>>     -[     +[+<     ]>    >+  ]<  ++  .>    >>    >>>>>>

And finally,
$ ./art UNCOPYRIGHTABLE

 +[  >+  <    +   ++]>    .>>>   >>>>>   >>  >>  >>>>>    >>>>    >+++   [[  -<  ]>>--]   <+.>   >>>>>   >>      >-[+>+
 <[  +<  ]>   ]  >+  ++  .>  >>  >>  >>  >+  ++  [[  -<    ]>    >-  -]  <+  +.    >>    >>  >>  >>  >>  >>      >>
 >+  ++  [ [- <  ]>      >-  -]  <+  ++  .>  >>  >>  >>    >>    -[      +[  +<    ]>    >+  ]<  +.  >>  >>      >>
 >>  >>  + [> +  <+      ++  ]>  --  --   +.>>   >>  >>    >>    >>      >>>>>>    >>    +[>+<+  +++++   +]      >.>>>
 >>  -[  + [> -  --      <<  ]>  +]>-+     +.    >>>>>     >>    >> >-[  +[>---    <<    ]>+]>-  +++.>   >>      >>>>>
 >>  >>  > >> >  +[      >+  <+  ++        ]>    --  --    ++    +.  >>  -[  +>    +<    [+  <]  >]  >+  .>      >>
 >>  >>  >   >>  >>  >>  >>  >>  >>        >-    [+  >+    <[    +<  ]>  ]>  ++    .>    >>  >>  >>  >>  >>      >>
  >>>>   >    >   >+[>    +<++   ++        ++    +]  >+   ++.>    >-[+   [>  --    -<    <]  >+  ]>-.>   >>>>>>  >>>>>>


text:
Generate Ulam Numbers
Given an integer n (where n < 10001) as input, write a program that will output the first n Ulam numbers. An Ulam number is defined as follows:

U1 = 1, U2 = 2.
For n > 2, Un is the smallest integer which is greater than Un-1 that is the sum of two distinct earlier terms in exactly one way.

For example, U3 is 3 (2+1), U4 is 4 (3+1) (note that (2+2) does not count as the terms are not distinct), and U5 is 6, (U5 is not 5 because 5 can be represented as either 2+3 or 4+1). Here are the first few Ulam numbers:

1, 2, 3, 4, 6, 8, 11, 13, 16, 18, 26, 28, 36, 38, 47, 48, 53, 57, 62, 69, 72, 77, 82, 87, 97, 99

This is code golf, so the shortest entry wins.

Does the output have to be as shown (list separated by comma and space) or can we output e.g., an array?

What's the minimum value of n we have to handle?

@Dennis Space or comma or both is fine. Minimum value of n is 1.

As it is, I have brackets around my list. Is that OK too or should I remove them?

@Dennis Brackets are fine.

I just spent a few minutes making a big ugly Brachylog solution only to realize that it gets the sequence wrong after 57...

CJam, 47 41 37 bytes
li4,1${__m*{_~<\:+*}%$2/z:^$2=+}*1><`

Try it online.
Example run
$ cjam <(echo 'li4,1${__m*{_~<\:+*}%$2/z:^$2=+}*1><`') <<< 26
[1 2 3 4 6 8 11 13 16 18 26 28 36 38 47 48 53 57 62 69 72 77 82 87 97 99]

How it works
This basic idea is the following:

Start with the array A := [ 0 U₁ U₂ ... Uₖ ].
Compute S, the array of all sums x + y such that x,y ∊ A and x < y.
Discard all non-unique sums from S. Since every Ulam number greater than 2 is both the sum of two smaller ones and the sum of zero and itself, this discards the Ulam numbers U₃, U₄, ... Uₖ.
The remaining array is [ U₁ U₂ Uₖ₊₁ ... ], so the next Ulam number is the third smallest element. Append it to A and go back to step 1.

li                                    " Read one integer (I) from STDIN.                  ";
  4,                                  " Push the array A = [ 0 1 2 3 ].                   ";
    1${                        }*     " Do the following I times:                         ";
       __m*                           " Push the Cartesian product A × A.                 ";
           {       }%                 " For each pair (x,y) in A × A:                     ";
            _~<\:+*                   " Compute (x + y) * (x < y).                        ";
                     $2               " Sort the resulting array.                         ";
                       /              " Split it into chunks of length 2.                 ";
                        z             " Transpose the resulting two-dimensional array.    ";
                         :^           " Compute the symmetric difference of its rows.     ";
                           $          " Sort the resulting array.                         ";
                            2=        " Extract its third element.                        ";
                              +       " Push it on the array A.                           ";
                                 1>   " Discard the first element of A (0).               ";
                                   <  " Discard all but the first I elements of A.        ";
                                    ` " Push a string representation of A.                ";

An input of 100 already takes several seconds. I suppose computing the maximum input 1e5 would take ages?

@MartinBüttner: The Java interpreter is a lot faster, but it's still slow. All brute-force algorithms are O(n²) or worse. Using a stack-oriented language for arrays is never pretty (e.g., computing an arrays length requires copying the entire array), so actual execution time is probably O(n³).

@MartinBüttner: WolframAlpha, so 1e4 (thankfully, not 1e5) should take less than three weeks.

J - 46 char
Function taking n as argument.
_2}.(,]<./@-.~</~({.+_*1<#)/.~@#&,+/~)@[&0&1 2

Explained by explosion:
    (                                )          NB. procedure for a list:
                                  +/~           NB.   take an addition table
              </~              #&,              NB.   select the top right half (no diag)
                 (        )/.~@                 NB.   for each unique value:
                       1<#                      NB.     if more than one present
                  {.+_*                         NB.     add infinity to it
      ]    -.~                                  NB.   remove existing Ulam numbers
       <./@                                     NB.   take the smallest
     ,                                          NB.   append to Ulam numbers
                                      @[&0      NB. repeat this procedure:
                                          &1 2  NB.   n times starting with [1, 2]
_2}.                                            NB. drop the last two numbers

There's +_*...

T-SQL, 301 300 288 287
I've committed a little light SQL abuse.
DECLARE @N INT=100,@T INT=1DECLARE @ TABLE(I INT,U INT)INSERT @ VALUES(1,1),(2,2)#:IF @T>2INSERT @ SELECT TOP 1@T,A.U+B.U FROM @ A,@ B WHERE A.U>B.U GROUP BY A.U+B.U HAVING COUNT(*)=1AND A.U+B.U>ALL(SELECT U FROM @)ORDER BY 2SET @T+=1IF @T<=@N GOTO # SELECT U FROM @ WHERE I<=@N ORDER BY I

Try it in SQL Server 2008 here.
@N holds the input integer.  Change the example "100" to what n should be.  "10000" will probably finish eventually, but I haven't let that run to completion.  This entry's char count is for a one-digit input.  Output is in query result form.

Haskell, 70 67 characters
u n=take n$1:2:[x|x<-[1..],[_]<-[[y|y<-u$n-1,z<-u$n-1,y<z,y+z==x]]]

usage:
>u 6
[1,2,3,4,6,8]

JavaScript ES6, 100 ... 93 90 characters
Run this in Web Console or Scratchpad of latest Firefox (Nightly or release).
EDIT 8 Golfed a lot!!! and made it down to 94 characters 93 90 characters (thanks to @openorclose). (My first sub 100)
Here is my version which is much faster but is 3 characters longer (107 characters) and is exactly the same amount of characters as above and is much smaller than the brute force method below!, (thanks to edc65 ) :
u=n=>(s=>{for(r=[i=l=1];c=l<n;i+=c&&i-2?1:s[r[l++]=i]=1)r.map(j=>c-=j<i/2&s[i-j])})([])||r

I will keep trying to golf it further. But we are squeezing it out of the scope of JS :P
Here are some numbers when I run this inside a script tag in a webpage:

n           time (s)
10            0.001
100           0.005
1000          2.021
10000       236.983
100000      pending tldr; Too long didn't run :P

This is my first submission which is heavily inspired by @rink.attendant.6's answer in JavaScript.
u=n=>{for(l=[1,g=2],i=3;g<n;++i){z=1;for(j of l)for(k of l)z-=j<k&j+k==i;!z?l[g++]=i:0}return n>1?l:[1]}

I know this can be golfed even further. I will post a non-bruteforced solution too, which might be even shorter.
EDIT 1: Golfed a bit more and fixed for n = 1
I must say that I do envy Haskell and J for such super handy shortcuts for every kind of requirement -_-

about Haskell, i think the functional style and the syntax make most the difference (for example, no hideous giant loops), although the amount of functions is always nice :-)

smart and fast, but does not work for n==1

The faster one can surely be golfed more: (104) u=n=>{for(s=[,1,1],r=[i=1,l=2];c=l<n;!c?s[r[l++]=i]=1:0,i++)for(j of r)c-=j<i/2&s[i-j];return n>1?r:[1]} and maybe even more

I still barely understand how you avoided the double loop.Kudos 2.Golf tip:in E6 I always try to avoid return. 100:u=n=>(s=>{for(r=[i=1,l=2];c=l<n;i+=!c?s[r[l++]=i]=1:1)for(j of r)c-=j<i/2&s[i-j]})([,1,1])|n>1?r:[1]

There one less char: u=n=>(s=>{for(r=[i=l=1];c=l<n;i+=c&&i-2?1:s[r[l++]=i]=1)for(j of r)c-=j<i/2&s[i-j]})([,1])||r

@openorclose - U DA MAN

90 chars: u=n=>(s=>{for(r=[i=l=1];c=l<n;i+=c&&i-2?1:s[r[l++]=i]=1)r.map(j=>c-=j<i/2&s[i-j])})([])||r
Unless the [,1] is needed somewhere

Perl - 71 bytes
#!perl -p
@a=$b[2]=1;1while$b[++$a]^1||$_>map(++$b[$_+$a],@a)&&push@a,$a;$_="@a"

Try it online!
Counting the shebang as one.
Using a second array to store the sums seems to be significantly faster than a hash. Memory usage is also less, which I wouldn't have expected.
Sample usage:
$ echo 30 | perl ulam.pl

Sample output:
1 2 3 4 6 8 11 13 16 18 26 28 36 38 47 48 53 57 62 69 72 77 82 87 97 99 102 106 114 126

Approximate runtimes:
n = 100     0.015s
n = 1000    0.062s
n = 10000   4.828s

8.6 s for n == 1e4. Amazing! The output for n == 1 is incorrect though; it should print a single number.

@Dennis now fixed.

GolfScript (41 37 bytes)
~.14*,3,\{1$.{2$1$-.@<*}%&,2=*|}/0-<`

Online demo
Cartesian products in GolfScript are quite long, so this takes a different approach. The long-term growth of the Ulam numbers is that the nth Ulam number is about 13.5n, but in the first 10000 terms the greatest ratio between the nth Ulam number and n is just under 13.3. So given n we can filter the first 14n numbers to find those which belong in the sequence.
With thanks to Dennis for 41->37.

This is quite fast. n = 1000 takes under a minute with GolfScript; a port to CJam completes n = 1000 in 8 seconds and n = 10000 in 1h 20 m. -- You can save four bytes by combining your approach with mine, namely including 0 in the array and discarding it afterwards. That allows using set union instead of the block and eliminates the need for a variable: ~.14*,4,\{1$.{2$1$-.@<*}%&,2=*|}/1><`

@Dennis, how many chars shorter is the CJam? I assume that none of the operations get longer, and I'm pretty sure it has a one-char alias for 14.

Yes, 14 is just E. But you need to read from STDIN, convert the integer to a singleton before performing set union (I'll file a bug report about that) and 2$ won't work in the inner loop since CJam modifies the stack after each iteration... I've tried several different tricks, but the shortest one was exactly 37 bytes: li4,1$E*{__{I1$-_@<*}%&,2=I*a|}fI1><`

Java, 259
import java.util.*;class C{public static void main(String[]a){List<Integer>l=new ArrayList<>();l.add(1);l.add(2);for(int i=3,z=0;l.size()<new Long(a[0]);i++,z=0){for(int j:l){for(int k:l){if(j<k&j+k==i)z++;}}if(z==1)l.add(i);}l.forEach(System.out::println);}}

Brute force works well for this.
import java.util.*;
class C {
    public static void main(String[] a) {
        List<Integer>l = new ArrayList<>();
        l.add(1);
        l.add(2);
        for (int i = 3, z = 0; l.size() < new Long(a[0]); i++, z = 0) {
            for (int j : l) {
                for (int k : l) {
                    if (j < k & j + k == i)
                        z++;
                }
            }
            if (z == 1)
                l.add(i);
        }
        l.forEach(System.out::println);
    }
}

Printing the result seems to require Java 8, which might be worth mentioning. 2. The output for 1 should be a single number.

Does this handle an input of 10k?

I believe the j and k for loops don't need braces.

As Martin implies, I too would like to see a timed execution of this program for N = 10K .

APL (Dyalog Extended), 36 35 bytes
-1 byte by Adám
{⍵↑{⍵,⊃∧(∊⊢⊆⍨⍧⍨∊2 3⍨)⍵~⍨,+⍀⍨⍵}⍣⍵⍳2}

Try it online!
{⍵↑{⍵,⊃∧(∊⊢⊆⍨⍧⍨∊2 3⍨)⍵~⍨,+⍀⍨⍵}⍣⍵⍳2}      Monadic function taking an argument n:

{⍵,⊃∧(∊⊢⊆⍨⍧⍨∊2 3⍨)⍵~⍨,+⍀⍨⍵}   Helper function to compute the next Ulam number
                                    given ⍵ (the first few Ulam numbers)
                        +⍀⍨⍵      Make an addition table from ⍵.
                       ,          Flatten into a list.
                   ⍵~⍨            Remove all entries already in ⍵.

     (∊⊢⊆⍨2 3∊⍨⍧⍨)               Helper function taking an argument x:
                ⍧⍨                  The count of elts of x in itself
           2 3∊⍨                    1s where those counts are in (2 3), else 0s.*
       ⊢⊆⍨                          Partition x, removing values corresponding to 0s.
      ∊                             Join the partitions into a single list.

    (∊⊢⊆⍨⍧⍨∊2 3⍨)                Keep all elements that occur exactly 2 or 3 times.
                                  (i.e. that occur once as a
                                  sum of distinct elements of ⍵).
    ∧                         Sort ascending.
   ⊃                          Take the first value (the next Ulam #).
 ⍵,                           Append that value to ⍵.

{⍵↑{...}⍣⍵⍳2}
{  {...}⍣⍵  }                 Call the helper function n times
           ⍳2                 starting with (1 2). First n+2 Ulam numbers.
 ⍵↑                           Keep the first n elements.

When we make the addition table, diagonal elements are twice the entries in ⍵. Non-diagonal elements are sums of distinct elements, with each \$x\$ occurring twice for each way \$x\$ can be written as a sum of distinct elements. Therefore, each number \$x\$ occurs \$2a+b\$ times, where \$a\$ is the number of ways \$x\$ can be written as a sum of distinct elements from ⍵, and \$b\$ is 1 iff \$x\$ is twice some entry in ⍵. We want \$a=1\$, so it is sufficient to check \$2a+b \in \{ 2, 3\}\$.
* (In ngn/APL, a constant can end a train without using ⍨. But ngn/APL doesn't have count-in, so we need ⍨ somewhere.)

{(2 3∊⍨⍵⍧⍵)/⍵} → (∊⊢⊆⍨⍧⍨∊2 3⍨)

PHP 5.4+, 164
Same approach as my answers:
<?function u($n){for($l=[1,2],$i=3;count($l)<$n;++$i){$z=0;foreach($l as $j){foreach($l as $k){$z+=$j<$k&$j+$k==$i;}}if($z==1)$l[]=$i;}return array_slice($l,0,$n);}

Jelly, 20 bytes
Œc§ḟµḟœ-Q$Ṃɓ;
2RÇ⁸¡ḣ

Try it online!
Œc§ḟµḟœ-Q$Ṃɓ;    Helper link that appends the next number to x, a list of Ulam numbers:
Œc                  All unordered pairs of x
  §                 Sum each pair
   ḟ                Filter out the numbers already present in x.
    µ               Let this list be y. Then apply the following chain:

     œ-Q$Ṃ          Find the minimum of all unique elements.
     ḟ                Take y and filter out the elements in
      œ-Q$            the multiset difference between y and its unique elements.
          Ṃ           Then find the Ṃinimum of the result.

           ɓ;    Append (ɓ reverses argument order) the result to

2RÇ⁸¡ḣ           Main link:
2R               Start with [1,2].
  Ç⁸¡            Apply the helper link (Ç) n (⁸) times to generate n+2 Ulam #s.
     ḣ           Keep the first n values.

JavaScript, 147 154 150 (136)
Heavily inspired by @Ypnypn's brute-force Java solution posted earlier:
function u(n){for(l=[1,2],i=3;l.length<n;++i){z=0;l.forEach(function(j){l.forEach(function(k){z+=j<k&j+k==i})});if(z==1)l.push(i)}return l.slice(0,n)}

Thanks for @Dennis for shaving 4 to 18 bytes off my original version
Dangerous version (using for..in loops)
I would not recommend running this because looping through an object that is an instanceof Array using a for..in loop could cause your machine to burst into flames and/or transform into an angry killing machine, but here it is:
function u(n){for(l=[1,2],i=3;l.length<n;++i){z=0;for(j in l)for(k in l)z+=l[j]<l[k]&l[j]+l[k]==i;if(z==1)l.push(i)}return l.slice(0,n)}

Ungolfed
function u(n) {
    var l = [1, 2],
        i = 3,
        j, k, z;

    for (; l.length < n; ++i) {
        z = 0;
        l.forEach(function (j) {
            l.forEach(function (k) {
                if (j < k & j + k === i) {
                    z++;
                }
            });
        });
        if (z === 1) {
            l.push(i);
        }
    }

    return l.slice(0, n);
}

The output for 1 should be a singleton.

@Dennis Thanks, corrected.

If you move z=0 inside the loop, you need it only once. 2. for(j in l)for(k in l)z+=l[j]<l[k]&l[j]+l[k]==i; is a lot shorter than the l.forEach approach.

CoffeeScript, 119 114
Lately I've been practising CoffeeScript to improve at golfing JavaScript, so here's my JavaScript answer compiled into CoffeeScript:
u=(n)->l=[1,2];i=3;z=0;(for j in l
 for k in l
  z+=j<k&j+k==i
l.push(i) if z==1;++i;z=0)while l.length<n;l[..n-1]

I don't understand loops and comprehensions in CoffeeScript very well so perhaps this can be golfed further but it's what I have for now. Newlines are counted as one character (Unix style).

Mathematica, 107 91 bytes
Nest[#~Append~Min@Cases[Tally[Tr/@#~Subsets~2],{n_,1}:>n]&,{1,2},i=Input[]]~Drop~{3}~Take~i

It's a very direct implementation of the spec.

Find all pairs.
Delete all duplicates.
Delete all numbers less than the last Ulam number.
Append the minimum to the list.

I'm also applying Dennis's trick of including sums with 0, but the catch is that this makes the third element of the list 0 before resuming as one would expect, so I need to remove that element from the list.
It handles an input of 1000 in a few seconds, but I doubt that you'll get a result for 10k in a reasonable amount of time. But I don't think any of the others performs well on that either.

OCaml - 254 Characters
The code use an hash table to store the sum of the current elements of the list and update it each time a new element is computed.
open Hashtbl let h=create 7 let()=add h 3 1 let rec r n i l=if n=0then List.rev l else if mem h i&&find h i=1then(List.iter(fun x->if mem h(x+i)then replace h(x+i)2else add h(x+i)1)l;r(n-1)(i+1)(i::l))else r n(i+1)l let u n=if n=1then[1]else r(n-2)3[2;1]

Usage:
Within OCaml interpreter:
# u 26;;
- : int list =
[1; 2; 3; 4; 6; 8; 11; 13; 16; 18; 26; 28; 36; 38; 47; 48; 53; 57; 62; 69;
 72; 77; 82; 87; 97; 99]

Ungolfed
open Hashtbl
let h = create 7
let() = add h 3 1
let rec r n i l =
  if n=0 then List.rev l
  else if mem h i && find h i=1 then
    begin
      List.iter
        (fun x-> if mem h(x+i) then replace h (x+i) 2 else add h (x+i) 1)
        l;
      r (n-1) (i+1) (i::l)
    end
  else r n (i+1) l

let u n = if n=1 then [1] else r (n-2) 3 [2;1]

Python, 137 128 126 characters.
U,i=[1,2],2
for _ in [[0]]*(input()-2):
 t=_*3*i
 for a in U:
  for b in U:t[a+b]+=a!=b
 i=t[i+1:].index(2)+i+1;U+=[i]
print U

This is my first golf, and I've brought it down from ~250 characters, I'm pretty happy but would love suggestions on how to improve!

Minor, but worthwhile: combine lines 5&6 to for b in U:t[a+b]+=a!=b and lines 8&9 to while t[i]-2:i+=1

Thanks for the suggestion! I also changed the while loop to an index but it didn't save as many characters as I was expecting.

2 more chars: init U to [1], and move line 7 to after the for

You can still get rid of 2 chars by changing U,i=[1,2],2 to U,i=[1],2 and input()-2 to input()-1 and t=_*3*i to t=_*3*i;U+=[i] and remove ;U+=[i] at end of for

C#, 257
Brute force approach, using LINQ:
using System.Linq;class U{void F(int n){var u=n<2?new int[]{1}:new int[]{1,2};for(int i=3;u.Length<n;++i)if(u.SelectMany(x=>u,(a,b)=>new{A=a,B=b}).Count(x=>x.A>x.B&&x.A==i-x.B)==1)u=u.Union(new int[]{i}).ToArray();System.Console.Write(string.Join("",u));}}

Ungolfed, With Test Harness
using System.Linq;
class Ulam
{
    void F(int n)
    {
        //handle special case where n = 1 (ugh)
        var u = n < 2 ? new int[] { 1 } : new int[] { 1, 2 };
        for (int i=3; u.Length<n; ++i)
            if (u.SelectMany(x => u, (a, b) => new { A = a, B = b })
                     .Count(x => x.A > x.B && x.A == i - x.B) == 1)
                u = u.Union(new int[] { i }).ToArray();
        System.Console.Write(string.Join(" ",u));
    }
    public static void Main(string[] args)
    {
        new Ulam().F(1);
        System.Console.WriteLine();
        new Ulam().F(2);
        System.Console.WriteLine();
        new Ulam().F(3);
        System.Console.WriteLine();
        new Ulam().F(26);
        System.Console.WriteLine();
    }
}

Very slow: 46s for n=500, 6m for n=1000, 50m for n=2000.  At that exponential rate, I believe it will take 5 or 6 days to process n=10K.

Pyth, 27 25 bytes
<uaGh-sfq1lT.gksM.cG2GQS2

Try it online here.
<uaGh-sfq1lT.gksM.cG2GQS2Q   Implicit: Q=eval(input())
                             Trailing Q inferred
 u                    Q      Perform the following Q times...
                       S2    ... with G initialised to [1,2]:
                 .cG2          Get all 2-element combinations of G
               sM              Sum each pair
            .gk                Group them by value
                                 The groups are sorted by the result of the sum
       f                       Filter the groups, as T, keeping those where:
          lT                     Length of T
        q1                       Equal to 1
      s                        Flatten list
     -               G         Remove elements of the above which are already in G
    h                          Take the first of the remaining elements
                                 This is the smallest, as the grouping also sorted them
  aG                           Append this to G
<                        Q   Take the first Q elements, implicit print

Edit: golfed 2 bytes by performing summation before grouping. Previous version: <uaGh-mssdfq1lT.gsk.cG2GQS2

C, 478 bytes
#define R return
bs(x,v,l,h,r)unsigned x,*v,l,h,*r;{unsigned m;for(;l<=h;){m=(l+h)/2;if(x<v[m])h=m-1;else if(x>v[m])l=m+1;else{*r=m;R 1;}}*r=m;R 0;}
#include<stdlib.h>
unsigned*f(unsigned w){unsigned*u=0,i,k,m,y,z;if(w>1E6||w==0)R u;u=malloc(w*sizeof*u);if(!u)R u;k=0;u[k++]=1;if(w==1)R u;m=u[k++]=2;if(w==2)R u;l:for(i=0,y=0,z=k-1,++m;i<k;y+=bs(m-u[i],u,i+1,z,&z),++i)if(y>1||u[i]+(i+1!=k?u[i+1]:0)>m)break;if(m==0){free(u);u=0;R u;}if(y!=1)goto l;u[k++]=m;if(k< w)goto l;R u;}

In Tio now in 9 seconds it would find 10000 values (and in there print the first 100 values). The trick is using not linear search in the inner loop but binary search...
These below are functions well indented and full readable (at last for me):
bsCopy(x,v,l,h,r)unsigned x,*v,l,h,*r;
{unsigned m;
 for(;l<=h;){m=(l+h)/2;if(x<v[m])h=m-1;else if(x>v[m])l=m+1;else{*r=m;R 1;}}
 *r=m;R 0;// in *r if return 0 the min index that fail else the index of find x
}

unsigned*fCopy(unsigned w)
{unsigned*u=0,i,k,m,y,z;
 if(w>1E6||w==0)R u;
 u=malloc(w*sizeof*u);
 if(!u)R u;
 k=0;u[k++]=1;if(w==1)R u;
   m=u[k++]=2;if(w==2)R u;//below I suppose m-u[i] is in the range (if exist in u) (i+1)..z
 l: for(i=0,y=0,z=k-1,++m;i<k;y+=bsCopy(m-u[i],u,i+1,z,&z),++i)
          if(y>1||u[i]+(i+1!=k?u[i+1]:0)>m)break;
   if(m==0){free(u);u=0;R u;}
          if(y!=1)goto l;
   u[k++]=m;if(k< w)goto l;
 R u;
}

See if I can reduce something...

Something say me that in programming  golfing is ok but it is not all...

328 bytes

@ceilingcat "z=k" for me is wrong because binary search (bs() function or your B()function) seems to me want as argument ranges (I don't know if it is right too...) so in the function who call bin search it has to be z=k-1

APL(NARS), 278 char, 556 bytes
∇u←p w;m;y;i;k;z;r;bs
bs←{(x l h)←⍵⋄l>h:0,h⋄x<⍺[t←⌊2÷⍨l+h]:⍺∇x,l,t-1⋄x>⍺[t]:⍺∇x,(t+1),h⋄1,t}
u←⍬  ⋄→0×⍳(w>1E6)∨w≤0
u←u,1⋄→0×⍳w=1
u←u,2⋄→0×⍳w=2⋄k←m←2
i←1⋄y←0⋄m+←1⋄z←k
→7×⍳(y>1)∨i>k⋄→7×⍳m<u[i]+{i=k:0⋄u[i+1]}⋄r←u bs(m-u[i]),(i+1),z⋄y+←↑r⋄z←2⊃r⋄i+←1⋄→6
→5×⍳y≠1⋄u←u,m⋄k+←1⋄→5×⍳k<w
∇

it would be the translation in APL of C one I sent.
It seems i not understand when to use ∇∇ in place of ∇... possible ∇∇ is used when there is one
argument is one function (and not one other type).
"u bs x, a,b" should be the bin search in "u" array for the value "x" in the range a..b; it would return 1, indexWhereFind
or 0, indexWhereEndOfsearch. With argument 200 p function take +- a minute here...
  p 100
1 2 3 4 6 8 11 13 16 18 26 28 36 38 47 48 53 57 62 69 72 77 82 87 97 99 102 106 114 126
  131 138 145 148 155 175 177 180 182 189 197 206 209 219 221 236 238 241 243 253
  258 260 273 282 309 316 319 324 339 341 356 358 363 370 382 390 400 402 409 412
  414 429 431 434 441 451 456 483 485 497 502 522 524 544 546 566 568 585 602 605
  607 612 624 627 646 668 673 685 688 690
  p¨1 2 3 4
1  1 2  1 2 3  1 2 3 4

∇∇ in a dop refers to the operator itself while ∇ refers to the derived function consisting of the operator with its operand(s). So in a monadic operator ∇ is the same as (⍺⍺∇∇) while in a dyadic operator it means (⍺⍺∇∇⍵⍵).


text:
Draw Concentric ASCII Hexagons
Write the shortest program possible that takes in a set of distinct positive integers and outputs an ASCII rendering of concentric hexagons with those side lengths, made from slashes, underscores, spaces, and newlines.
The shortest program in bytes as counted by https://mothereff.in/byte-counter wins.
Examples
(They look better with less line spacing.)
If the input is 1 the output should be the hexagon with side length 1:
 __
/  \
\__/

Notice that two underscores are used for the top and bottom of the hexagon so it is better proportioned.
In general, the size N hexagon contains N slashes on each angled side and 2*N underscores on on both the top and bottom.
If the input is 1 2 the output should be the concentric hexagons with side length 1 and 2:
  ____
 / __ \
/ /  \ \
\ \__/ /
 \____/

If the input is 1 3 the output should be:
   ______
  /      \
 /   __   \
/   /  \   \
\   \__/   /
 \        /
  \______/

If the input is 1 3 2 the output should be:
   ______
  / ____ \
 / / __ \ \
/ / /  \ \ \
\ \ \__/ / /
 \ \____/ /
  \______/

etc.
I/O Rules
Input must come from either the command line or stdin but may be in whatever format is most convenient.
For example, you might give each number as a command line argument: > myprogram 1 3 2, or you might prompt the user to input the numbers as a preformatted list: [1, 3, 2].
Output must go to stdout or your language's closest equivalent.
Additional Rules

The input will always be a set of distinct positive integers, not necessarily in any order.
The output must...

not contain any characters besides /\ _ and newlines.
have no trailing spaces or unnecessary leading spaces.
not contain extraneous leading newlines but may have one optional trailing newline.

If nothing is input then output nothing (except possibly one newline).
If it helps you may assume that the input integers are less than 216.

Does the 1 refer to the innermost or outermost hexagon?

@hsl The 1 (or any number) refers to the hexagon with side length of 1. (With the caveat that 1 slash = 2 underscores.) So 1 will always refer to the innermost hexagon.

CJam, 148 116 109 bytes
This took a lot longer than I expected. Originally, I just wanted to iteratively build the upper left quadrant, as in the diamond challenges, and then get the rest from mirroring. But I didn't notice that the underscores don't obey mirror symmetry between the upper and lower half. So I had to redo most of that, to generate the right half iteratively and then only mirror once (to the left).
S]2[l~]:(f#:+2bW%{_,2/~:T;{IT):T1<'\'/?S?S++}%__,2/=,2/I'_S?*_S+a@+\I'/S?S++a+}fI{)T)2*2$,-*1$W%"\/"_W%er@N}/

Test it here.
A Fibonacci-esque example:
8 3 1 5 2

        ________________
       /                \
      /                  \
     /     __________     \
    /     /          \     \
   /     /   ______   \     \
  /     /   / ____ \   \     \
 /     /   / / __ \ \   \     \
/     /   / / /  \ \ \   \     \
\     \   \ \ \__/ / /   /     /
 \     \   \ \____/ /   /     /
  \     \   \______/   /     /
   \     \            /     /
    \     \__________/     /
     \                    /
      \                  /
       \________________/

Explanation:
As stated at the top, I start by building the right half iteratively. That is, initially I've got only a single space in the grid, and then for each possible ring, I either surround the existing grid in spaces or a new semi-hexagon.
Once that's done, I mirror each line to the left and pad it with leading spaces for correct alignment. Here is a breakdown of the code:
"Prepare the input and the grid:";
S]2[l~]:(f#:+2bW%
S]                "Push string with a space and wrap it in an array. This is the grid.";
  2               "Push a 2 for future use.";
   [l~]           "Read and evaluate the input, wrap it in an array.";
       :(         "Decrement each number by 1.";
         f#       "Map each number i to 2^i.";
           :+     "Sum them all up.";
             2b   "Get the base two representation.";
               W% "Reverse the array.":
"At this point, the stack has the proto-grid at the bottom, and an array of 1s and
 0s on top, which indicates for each hexagon if it's present or not.";

"Next is a for loop, which runs the block for each of those 0s and 1s, storing the
 actual value in I. This block adds the next semi-hexagon or spaces.";
{ ... }fI

"First, append two characters to all existing lines:";
_,2/~:T;{IT):T1<'\'/?S?S++}%
_                            "Duplicate the previous grid.";
 ,2/                         "Get its length, integer-divide by 2.";
    ~:T;                     "Get the bitwise complement and store it in T. Discard it.";
        {                 }% "Map this block onto each line of the grid.";
         I                   "Push the current hexagon flag for future use.";
          T):T               "Push T, increment, store the new value.";
              1<'\'/?        "If T is less than 1, push \, else push /.";
                     S?      "If the current flag is 0, replace by a space.";
                       S++   "Append a space and add it to the current line.";

"So for hexagons this appends '\ ' to the top half and '/ ' to the bottom half.
 For empty rings, it appends '  ' to all lines.";

"Now add a new line to the top and the bottom:"
__,2/=,2/I'_S?*_S+a@+\I'/S?S++a+
__                               "Get two copies of the grid.";
  ,2/                            "Get its length, integer-divide by 2.";
     =                           "Get that line - this is always the middle line.";
      ,2/                        "Get ITS length, integer'divide by 2.";
         I'_S?*                  "Get a string of that many _ or spaces depending on the
                                  current flag.";
               _S+               "Duplicate and a space.";
                  a@+            "Wrap in an array, pull up the grid, and prepend the line.";
                     \           "Swap with the other copy.";
                      I'/S?      "Choose between / and a space depending on the flag.";
                           S++   "Append a space, and add both characters to the line.";
                              a+ "Wrap in an array, and append line to the grid.";

"This is all. Rinse and repeat for all rings. The result will look something like this:

_____
     \
___   \
__ \   \
_ \ \   \
 \ \ \   \
_/ / /   /
__/ /   /
___/   /
      /
_____/

Note that there are still trailing spaces.";

"Finish up all lines. These will not be joined together any more, but simply left
 on the stack in pieces to printed out back-to-back at the end of the program.
 The following runs the given block for each line:";
{ ... } /

"This generates the necessary indentation, then mirrors the lines and puts them
 in the right order:"
)T)2*2$,-*\_W%"\/"_W%er\N
)                         "Slice off that trailing space, but leave it on the stack.";
 T                        "Remember T? That still has something like the the size of
                           the grid from the last iteration. In fact it's N-1, where
                           N is the largest visible hexagon. We can use that to figure
                           out how many spaces we need.";
  )2*                     "Increment and double.";
     2$                   "Copy the current line.";
       ,-                 "Subtract its length from 2*N.";
         *                "Repeat the space that often. This is our indentation.";
          \_              "Swap with the line and duplicate.";
            W%            "Reverse the line.";
              "\/"_W%er   "Replace slashes with backslashes and vice versa.";
                       \  "Swap with the original line.";
                        N "Push a line break.";

Python - 251, 240, 239 228
l=input()+[0];m=max(l);A=abs;R=range
for j in R(2*m+1):print''.join([[' \\'[(A(j-i+m-1)/2.in l)*(2*m-i)/(j-m-.5)>1],'/'][(A(3*m-i-j)/2.in l)*(i-m-j+.5)/(j-.5-m)>0],'_'][(A(m-j)in l)*(A(2*m-i-.5)<A(m-j))]for i in R(4*m)).rstrip()

Alternative approach (251):
l=input()+[0]
l.sort()
m=max(l)
M=2*m
s=[[' ']*m*4for j in' '*(M+1)]
for i in l:
 I=2*i;s[m-i][M-i:M+i]=s[m+i][M-i:M+i]='_'*I
 for k in range(i):K=k+1;s[m-k][M-I+k]=s[m+K][M+I-K]='/';s[m-k][M+I-K]=s[m+K][M-I+k]='\\'
for t in s:print''.join(t).rstrip()

APL (222 bytes in UTF-8)
(and 133 chars)
Since this question specifically asks for amount of bytes in UTF8 representation, I had to actually ungolf it a bit so that it is longer but its UTF8 representation is shorter. (In particular, the commute operator's character ⍨ is three bytes while () is only two, so that optimalisation doesn't work anymore, and it also makes assignment very expensive.)
{⎕←(~⌽∧\⌽⍵=' ')/⍵}¨↓⊃{⍵{⍺=' ':⍵⋄⍺}¨K↑(-.5×(K←⍴⍵)+⍴⍺)↑⍺}/{Z⍪⌽⊖Z←↑(⊂(⍵/' '),(2×⍵)/'-'),⍵{((-⍵)↑'/'),((2 4-.×⍵⍺)/' '),'\'}¨⌽⍳⍵}¨N[⍋N←,⎕]

Previous version, which is shorter in characters (124) but uses more bytes when represented in UTF-8 (230, which would put it in second place):
M←' '⋄{⎕←⍵/⍨~⌽∧\⌽⍵=M}¨↓⊃{⍵{⍺=M:⍵⋄⍺}¨K↑⍺↑⍨-.5×(K←⍴⍵)+⍴⍺}/{Z⍪⊖⌽Z←↑(⊂(⍵/M),'-'/⍨2×⍵),⍵{('/'↑⍨-⍵),'\',⍨M/⍨2 4-.×⍵⍺}¨⌽⍳⍵}¨N[⍋N←,⎕]

Test:
      {⎕←(~⌽∧\⌽⍵=' ')/⍵}¨↓⊃{⍵{⍺=' ':⍵⋄⍺}¨K↑(-.5×(K←⍴⍵)+⍴⍺)↑⍺}/{Z⍪⌽⊖Z←↑(⊂(⍵/' '),(2×⍵)/'-'),⍵{((-⍵)↑'/'),((2 4-.×⍵⍺)/' '),'\'}¨⌽⍳⍵}¨N[⍋N←,⎕]
⎕:
      3 1 5 2
     ----------
    /          \
   /   ------   \
  /   / ---- \   \
 /   / / -- \ \   \
/   / / /  \ \ \   \
\   \ \ \  / / /   /
 \   \ \ -- / /   /
  \   \ ---- /   /
   \   ------   /
    \          /
     ----------

This doesn't seem to meet the spec for top and bottom sides (they should be underscores, not hyphens) and consequently be offset by one line for the bottom sides.

Perl 5, 352 (349 bytes + 3 for anE flags)
This could probably be golfed down a lot more..

@b=sort{$a>$b}@F;map{$_<$j||($j=$_)}@b;$k=++$j;for(;$j--;){$z=$"x$j;for($e=$k;--$e>$j;){$z.=$e~~@b?'/ ':'  '} $z.=($j~~@b?'_':$")x(2*$j);$z.=$_~~@b?' \\':'  'for($j+1..$k-1);say$z}for(0..$k-2){$z=$"x$_;for($e=$k;--$e>$_;){$z.=($e-$k+1?$":'').($e~~@b?'\\':$")}$z.=(($_+1)~~@b?'_':$")x(2*$_+2);$z.=($_~~@b?'/':$").($_-$k+1?$":'')for($_+1..$k-1);say$z}

Ungolfed:
# sort list of side lengths
@b=sort{$a>$b}@F;
# set $k and $j to max side length + 1
map{$_<$j||($j=$_)}@b;$k=++$j;
for(;$j--;){
  $z=$"x$j;
  for($e=$k;--$e>$j;){$z.=$e~~@b?'/ ':'  '}
  $z.=($j~~@b?'_':$")x(2*$j);
  $z.=$_~~@b?' \\':'  'for($j+1..$k-1);
  say$z
}
for(0..$k-2){
  $z=$"x$_;
  for($e=$k;--$e>$_;){$z.=($e-$k+1?$":'').($e~~@b?'\\':$")}
  $z.=(($_+1)~~@b?'_':$")x(2*$_+2);
  $z.=($_~~@b?'/':$").($_-$k+1?$":'')for($_+1..$k-1);
  say$z
}

Example (1 5 3 14):
              ____________________________
             /                            \
            /                              \
           /                                \
          /                                  \
         /                                    \
        /                                      \
       /                                        \
      /                                          \
     /                 __________                 \
    /                 /          \                 \
   /                 /   ______   \                 \
  /                 /   /      \   \                 \
 /                 /   /   __   \   \                 \
/                 /   /   /  \   \   \                 \
\                 \   \   \__/   /   /                 /
 \                 \   \        /   /                 /
  \                 \   \______/   /                 /
   \                 \            /                 /
    \                 \__________/                 /
     \                                            /
      \                                          /
       \                                        /
        \                                      /
         \                                    /
          \                                  /
           \                                /
            \                              /
             \____________________________/

C# - 388 316 bytes
Edit: Changed how it avoids printing trailing spaces and threw in some LINQ
Simple program that takes command line arguments. It iterates through every possible char in each line of a rectangle defined by the maximum hexagon dimension and appends it to the current line, before trimming the lines and printing them successively (it produces the optional trailing new-line).
Golfed Code:
using System.Linq;class P{static void Main(string[]A){var I=A.Select(int.Parse);int m=I.Max(),i,j,y,x;for(j=m+1;j-->-m;){var r="";for(i=-2*m-1;++i<2*m-(y=j<0?-j-1:j);)r+="/\\_- "[(x=i<0?-i-1:i)>y&(x+=y)%2>0&x/2<m&&I.Contains(x/2+1)?(i^j)&1:x-y<(y=j<0?-j:j)&y<=m&I.Contains(y)?j<0?2:3:4];System.Console.WriteLine(r);}}}

Ungolfed code:
using System.Linq; // all important

class P
{
    static void Main(string[]A)
    {
        var I=A.Select(int.Parse); // create int array

        for(int m=I.Max(),j=m+1,i,y,x;j-->-m;) // for each line...
        {
            var r=""; // current line

            for(i=-2*m-1;++i<2*m-(y=j<0?-j-1:j);) // for each char...
                r+="/\\_- "[// append something to the current line
                (x=i<0?-i-1:i)>y&(x+=y)%2>0&x/2<m&&I.Contains(x/2+1)?
                    (i^j)&1: // slashes as appropriate - I can't work out why this bit works, but it seems to
                x-y<(y=j<0?-j:j)&y<=m&I.Contains(y)?
                    j<0?2:3: // _ or - if required
                4]; // otherwise a space

            System.Console.WriteLine(r); // print current line
        }
    }
}

APL (Dyalog Classic), 151 bytes (93 with the classic APL encoding)
{a←0⍴⍨1 0+1 2×n←⌈/⍵⋄a[⊃,/i,¨¨⍵+⍵-1+i←⍳¨⍵]←1⋄a←(⊖⍪-)a⋄a[⊃,/(n+⍵,-⍵),¨¨,⍨i]←2⋄' /_\'[4|(⌽,-)a]}

Try it online!