text:
Stack a random number of cups into a perfect two dimensional pyramid (triangle)
You are given a certain number of cups (n). You are tasked with stacking these cups into a pyramid, with each row having one more cup than the row above it. The number you are given may or may not be able to be perfectly stacked. You must write a function that takes the total number of cups (n), and returns the following values. t, which is the total number of cups in the pyramid, and b, which is the number of cups on the bottom row. Your answer must be returned in the format of a string, as b,t.

n is a randomly generated, positive, finite, whole number.
b and t must also be positive, finite, and whole.
You may not use any libraries that aren't already built into your language of choice.
The pyramid is two dimensional, so instead of expanding out, it is linear, with each row adding only a single cup more than the last, instead of one with a square or triangular base.

In some potential cases:

If n=4, b=2 and t=3.
If n=13, b=4 and t=10.
If n=5000, b=99 and t=4950.

A verbose example in JavaScript:
var pyramid = function(n){
    var i;
    var t = 0;
    var b;
    for(i=0;i<=(n-t);i++){
        t += i;
        b = i;
    }
    console.log(b + ',' + t);
}

And a tiny example too:
p=function(n){for(t=i=0;i<=(n-t);i++){t+=i;b=i}return b+','+t}
Good luck!

um... what shape is the base of the pyramid? is it an equilateral triangle (1,4,10,20...) a square (1,5,14,30..) or a rectangle (yes this is possible, the pyramid has a ridge on top.)

@steveverrill I should have clarified that it's supposed to be a 2 dimensional shape, so a triangle is a more appropriate definition. So row 1 would have 1 cup, 2 would have 2, 3 would have 3, and so on. I apologize for the lack of clarity. I'm editing the question now.

@steveverrill From the examples given, it's not a pyramid at all, but a triangle, so {1,3,6,10...} or t=(b*b+b)/2

@Geobits That's precisely it.

What's the winning criterion? [tag:code-golf]?

@professorfish Yes. I just changed the question to reflect that.

GNU dc, 25 bytes
dc does not really have functions, but the closest thing is a macro.  This defines a macro which is stored in register m.  This pops the input n from the top of the stack (idiomatic for dc), and prints b,t to stdout as per the spec:
# 25 byte macro definition
[8*1+v1-2/ddn44P1+*2/p]sm

# Some test cases
4 lmx
9 lmx
10 lmx
11 lmx
13 lmx
5000 lmx

Output:
$ dc 2dpyr.dc
2,3
3,6
4,10
4,10
4,10
99,4950
$

Explanation:
This uses the same inverse of the triangle function used in some of the other numbers.  The triangle number n for base length b is given by:
n = b(b+1)/2

Rearranging into a quadratic in terms of b:
b² + b - 2n = 0

Plugging the coefficients {A=1, B=1, C=-2} into the quadratic formula gives:
b = (-(1) ± sqrt((1)²-4(1)(-2n))) / 2(1)

b = (-(1) ± sqrt(1+8n)) / 2

This translates to dc as follows:
[                         # Start a macro definition
 8*                       # Push 8 to the stack and multiply by n
                          #     (n is assumed to be next value on the stack)
   1+                     # Push 1 to the stack and add to 8n
     v                    # Take the square root
      1-                  # Push 1 to the stack and subtract from the square root
        2/                # Push 2 to the stack and divide to get the value of `b`
          dd              # Duplicate top of stack twice (value of `b`)
            n             # Pop top of stack and print value of with no newline
             44P          # Push ASCII value of ',' (comma) and print with no newline
                1+        # Push 1 to the stack and add 1 to `b`
                  *       # Multiply b by (b+1)
                   2/     # Push 2 the stack and divide to get the value of `t`
                     p    # Print value of `t` with a newline
                      ]   # End macro definition
                       sm # Store macro in `m` register

Note the quadratic formula introduces a ±, but the + root always gives us the answer we need.
Note also that dc's default precision is 0 decimal places, and positive numbers are always rounded down to the nearest whole number, which is exactly the rounding we need.

This is really cool!

Not bad golfing for a language invented almost 50 years ago!

I like the method of explaining how the code works.

Haskell, 64 68
This works out the base directly by inverting the triangular number formula, t = (b^2+b)/2, and calculating b = (sqrt(8*t+1) - 1) / 2.

f n=init.tail$show(b,div(b^2+b)2)where b=floor$(sqrt(8*n+1)-1)/2

And rather than constructing the string-based answer as show b++","++show t, it simply chops the brackets off the shown tuple.
Edit: calculating the new triangular number in place instead of declaring a new variable, t, saves 4 characters.

+1 for a better formula than mine uses. I can save 11 chars that way by eliminating the ugly checks in the return.

ES6 41
This is based on the comperendinous' formula:
Edit: Thanks to edc65's suggestions:
p=n=>''+[b=~-Math.sqrt(8*n+1)>>1,b++*b/2]

~- is nice, but >>1 is shorter than /2|0

Really, I hate the 'right' answer beeing surpassed by a loop (that could be a lot slower for big numbers). 41: p=n=>''+[b=~-Math.sqrt(8*n+1)>>1,b++*b/2]

Java
It's pretty simple to find triangle numbers. Here are three ways in Java, all under 90 chars, including a loopless version:
67
String x(int n){int t=0,b=0;for(;b<=n-t;t+=b++);return(b-1)+","+t;}

78
String y(int n){int b=1,t=1;for(;t<=n*2;t=b*b+b++);return(--b-1)+","+(t/2-b);}

89
String z(int n){int b=(int)Math.sqrt(n*2),t=(b*b+b)/2;return(t>n?b-1:b)+","+(t>n?t-b:t);}

Bravo. I tried using the Math.sqrt(n2) in my own solution before, but ran into some rounding issues in JS because I didn't implement the final checks as you did. Nor did I correctly get the (bb+b)/2 down.

I don't follow your math. Knowing that the number of items in a triangle of base b is (b*b+b)/2, you just have to solve a quadratic equation (best explained in the dc answer)

@edc65 It's how I reverse triangle numbers in my head. Knowing 2t=b*b+b, it's easy to show that floor(sqrt(2t))=b, since b*b+b lies between b*b and (b+1)*(b+1) (assuming b is positive, which it is). What screws it up is that n!=t, and this method doesn't work unless the number is actually triangular. As a result, I just kludged through an off-by-one check instead of doing it the other way. I thought about changing it later, but even with that change, it's not as short as the simple loop method in Java.

Pyth, 29
DAbKJ0W>b+JK~K1~JK)R++`K","`J

If the output format b, t instead of b,t is OK, then it's 28 characters:
DAbKJ0W>b+JK~K1~JK)R:`,KJ1_1

If (b, t) is OK, it's 23 characters:
DAbKJ0W>b+JK~K1~JK)R,KJ

Explanation:
def A(b):
 K=J=0
 while gt(b,plus(J,K)):
  K+=1
  J+=K
 return plus(plus(repr(K),","),repr(J))

Test run - (input, output):
DAbKJ0W>b+JK~K1~JK)R++`K","`Jj"\n"m,dAdL11

(0, '0,0')
(1, '1,1')
(2, '1,1')
(3, '2,3')
(4, '2,3')
(5, '2,3')
(6, '3,6')
(7, '3,6')
(8, '3,6')
(9, '3,6')
(10, '4,10')

Javascript ES6 - 39 41 43
Thought I'd try some recursion in hopes that it'd be smaller than the for loop.
f=(n,b=0,t=0)=>(n>b)?f(n-++b,b,t+b):b+','+t

Tried to shrink it by calculating the total rather than passing it but ended up the same length
f=(n,b=0)=>(n>b)?f(n-++b,b):b+','+(b+b*b)/2

Edit: Dropped another 2 with core1024's suggestion
f=(n,b=0,t=0)=>n>b?f(n-++b,b,t+b):b+','+t

Edit: In principal, I agree with edc65 about the 'right' answer and almost didn't try to a recursive loop assuming it would be have to be longer.  So I hate to take his improvement, but I will :)  Nice spy there!
f=(n,b=0)=>n>b?f(n-++b,b):b+','+b++*b/2

41 if you remove the parentheses around n>b.

JavaScript (ES6) – 47
p=n=>{for(t=i=0;i+t<n;)t+=i++;return i-1+','+t}

For now only works on Firefox. The following works on any recent browser at 55 bytes:
p=function(n){for(t=i=0;i+t<n;)t+=i++;return i-1+','+t}

This is derived from the example provided by the OP.

Wrong output format - "Your answer must be returned in the format of a string, as b,t."

@isaacg I was testing it with alert(), which automatically converts the array to a string. I've changed it.

You can pre-increment i, so it will be the correct value when the loop is done.

PYTHON: 76
def r(x,b,t):
 x-=b+1
 return r(x,b+1,t+b) if x>=0 else str(b)+','+str(t+b)

x-(b+1) can be shortened to x-b-1, or since you're not using x again, maybe x-=b+1 and use x instead of c.

Whoops, never thought of that.

PHP 145
<?$n=$argv[1];for($b=ceil($n/2);$b>0;$b--){for($k=$b-1;$k>0;$k--){$v=array_sum(range($k,$b));if($v>$n)continue 2;if($v==$n){echo "$b,$k";exit;}}}

Expanded:
<?
$n=$argv[1];
for($b=ceil($n/2);$b>0;$b--){
    for($k=$b-1;$k>0;$k--){
        $v=array_sum(range($k,$b));
        if($v>$n)continue 2;
        if($v==$n){
            echo "$b,$k";
            exit;
        }
    }
}

source: Stack Exchange

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

sort: votes


text:
Solve quadratic equation using only 3 variables and arithmetic
Write function which solves equation of degree less than or equal to 2 (ax^2 + bx + c = 0).
Input
Function should get 3 parameters - floating point numbers which are coefficients of this equation. Coefficients may be zero (that means function must able to solve bx + c = 0 and c = 0 too).
Coefficients are between -1000 and 1000 with 3 significant decimal digits but maximum 3 digits after comma, for example, 999. or 3.14 or 0.233 but not 1001 or 0.0123.
Rules

You may use only + - * / % & | xor ~ && || ! < > >= <= == != << >> operators
No built-in functions (that means no square root or power or similar functions)
No variables except 3 function parameters
You can't use complicated expressions - only statements of the form a = b @ c or a = @ b are allowed (@ - any allowed operator and a, b, c - any variables, may be same or constants)
No loops, recursion, goto's, custom types
Casts and type conversion between integral data types are allowed
Using features of dynamic typing (changing floating point number to array/object/something else that is not number) is not allowed
If's are allowed with one or none operators in condition (if (a) {...} else {...} or if (a==b) {...} else {...}). Note that if itself and its condition scores separately
You may use try{}catch{}

Output

Output should be passed by reference to input variables, if your language doesn't have such feature, you anyway should put result to input variables and print their values
In variable a - number of real roots - 0, 1, 2, 3 (value greater than 2 stands for infinitely many roots)
In variables b and c - 1st and 2nd roots (if none or infinitely many roots than any values, if one root then c - any value)
Note that 2 equal roots is not the same as 1 root
Precision should be at least 3 significant decimal digits

Score

Score is [number of operators] + [number of if's]. Assignment operators have score 0.
Answer with lowest score wins.
In case of same score answer with greater precision wins. If precision is same then first answer wins.
if(a != 0) and if(a == 0) has score 1 (instead of 2) because if(a) or if(a)else{} can be used, however not all languages support it.
For each catch{} +2 to score
Use of 1 temporary variable of numeric type is +20 to score.

Comments are not for extended discussion; this conversation has been moved to chat.

If I write an answer in Java, what is the score cost for catching exceptions?

"Precision should be at least 3 significant decimal digits": what does this mean when the exact value of the root is 0?

@PeterTaylor 0.00. In this case, let first digit before comma be significant.

Hybrid of iterative approaches; score: 62
I originally posted an answer which purely used Newton-Raphson; however, in the cases of large b and c this requires a lot of iterations. Consider only the most interesting quadratics: those which have two solutions. If we normalise them to the form x^2 + bx + c = 0 then we can plot the number of iterations required for various approaches as a function of b and c. For example, we can modify the continued fraction route to get the direct approach:
c = -c;
a = b * 0.5;
while (loopCount-- > 0) { // This loop would be unrolled in the final solution
    a = a + b;
    a = c / a;
}
// Roots are a and -c/a

That gives a loop count diagram of
2236...................6322
2224n.................n4222
22236.................63222
22224n...............n42222
222236...............632222
222224m.............m422222
2222236.............6322222
2222224j...........j4222222
22222234P.........P43222222
22222223d.........d32222222
222222222t.......t222222222
2222222225Z.....Z5222222222
22222222219/////91222222222
/////////////./////////////
222222222*********222222222
222222222*********222222222
22222222***********22222222
22222223***********32222222
2222223*************3222222
2222224*************4222222
222223***************322222
222224***************422222
22223*****************32222
22224*****************42222
2223*******************3222
2224*******************4222
223*********************322

where c is negative in the first row and increases downwards, b increases from left to right, * means negative discriminant, / means only one root was within tolerance in 62 iterations, . means no root was within tolerance in 62 iterations, and numbers are in base-62 with digits 0-9a-zA-Z. This is pretty decent for a certain range, but fails completely for another range.
bmarks' original implementation is similar to (but not the same; this is a reimplementation from the continued fraction):
a = b;
while (loopCount-- > 0) {
    a = c / a;
    a = b - a;
}
// Roots are -a, -c/a (which is better than a-b)

with loop count diagram
1117...................7111
1112n.................n2111
11117.................71111
11112n...............n21111
111117...............711111
111112m.............m211111
1111117.............7111111
1111112j...........j2111111
11111115Q.........Q51111111
11111111d.........d11111111
111111113u.......u311111111
1111111116/...../6111111111
1111111111a/////a1111111111
1111111111111.1111111111111
111111111*********111111111
111111111*********111111111
11111111***********11111111
11111112***********21111111
1111111*************1111111
1111112*************2111111
111111***************111111
111113***************311111
11111*****************11111
11113*****************31111
1111*******************1111
1113*******************3111
111*********************111

My naïve N-R was quite bad, but the really interesting thing to note about it is where the worst areas are:
njfdcccccccccccccccccccdfjn
njgcbbbbbbbbbbbbbbbbbbbcgjn
njgc9999999999999999999cgjn
njgc9777777777777777779cgjn
njgc9666666666666666669cgjn
njgc9544444444444444459cgjn
njgc9521111111111111259cgjn
njgc9534444444444444359cgjn
njgc9535555555555555359cgjn
njgc9536777777777776359cgjn
njgc9536888888888886359cgjn
njgc9536899999999986359cgjn
njgc95368aaaaaaaaa86359cgjn
njgc95368aaaaaaaaa86359cgjn
njgc95368*********86359cgjn
njgc95369*********96359cgjn
njgc9536***********6359cgjn
njgc9536***********6359cgjn
njgc953*************359cgjn
njgc954*************459cgjn
njgc95***************59cgjn
njgc94***************49cgjn
njgc9*****************9cgjn
njgc8*****************8cgjn
njgc*******************cgjn
njgb*******************bgjn
njf*********************fjn

So the thing to do is to hybridise. For the areas where it's good, I use the continued fraction; for the rest, I use N-R, but I've done some optimisation: I've experimentally found two cutoffs and three initial values which converge in 5 iterations to a worst-case mixed error abs(value - correct_value) / (1 + abs(correct_value) of 0.000052. (Thanks to Martin Büttner for the idea of doing a case split). The final loop count (mixing the two cases into one diagram) is:
111555555555555555555555111
111233333333333333333332111
111133333333333333333331111
111125555555555555555521111
111115555555555555555511111
111112333333333333333211111
111111333333333333333111111
111111255555555555552111111
111111144444444444441111111
111111112111111111111111111
111111113222222222211111111
111111111333333333111111111
111111111444444444111111111
111111111111111111111111111
111111111*********111111111
111111111*********111111111
11111111***********11111111
11111112***********21111111
1111111*************1111111
1111112*************2111111
111111***************111111
111113***************311111
11111*****************11111
11113*****************31111
1111*******************1111
1113*******************3111
111*********************111

and the code is
solve_quad(&float a, &float b, &float c) {
    float t; // 20 points
    if (a != 0) { // 21
        if (c == 0) {
            // x(x+b) = 0
            b = -b; // 22
            a = 2;
        }
        else {
            // Normalise so that we're solving x^2 + bx + c = 0 and have `a` free to use
            // Hereon, mentions of b and c in comments refer to these normalised values.
            b = b / a; // 22
            c = c / a; // 23

            // Three cases:
            //   b^2 < 4c: negative determinant, no solutions
            //   b^2 < -4c: use Newton-Raphson
            //   Otherwise: use the continued fraction method that bmarks was the first to post

            a = b / 2; // 24
            a = a * a; // 25
            if (a < c) { // 26
                a = 0;
            }
            else {
                t = a + c; // 27
                if (t < 0) { // 28
                    c = a - c; // 29, c holds the determinant

                    // Carefully optimised case split:
                    if (c < 0.05) // 30
                        a = 0.025;
                    else if (c < 250) // 31
                        a = 2;
                    else a = 193;

                    t = c / a; a = a + t; a = a / 2; // 34
                    t = c / a; a = a + t; a = a / 2; // 37
                    t = c / a; a = a + t; a = a / 2; // 40
                    t = c / a; a = a + t; a = a / 2; // 43
                    t = c / a; a = a + t; a = a / 2; // 46

                    // At this point a ~= sqrt(determinant)
                    t = b / 2; // 47
                    a = a + t; // 48
                    t = t * t; // 49
                    c = t - c; // 50
                    // At this point a ~= b/2 + sqrt(determinant) and c holds its original value
                }
                else {
                    a = b;

                    a = c / a; a = b - a; // 52
                    a = c / a; a = b - a; // 54
                    a = c / a; a = b - a; // 56

                    // At this point a ~= b/2 + sqrt(determinant)
                }

                b = -a; // 57
                c = c / b; // 58
                a = 2;
            }
        }
    }
    else {
        // bx + c = 0
        if (b != 0) { // 59
            a = 1;
            c = -c; // 60
            b = c / b; // 61
        }
        else {
            // c = 0
            if (c != 0) a = 0; // 62
            else a = 3;
        }
    }
}

Where do you take care of negative or zero discriminants?

@user2992539, fixed.

Advice: in the beginning you can divide b by -2 to avoid in future b = -b.

@user2992539 ummm... I think I asked you about coercing unary operators into binary operations and you said I needed to separate them.

@MartinBüttner -b is unary operator, however -2 is constant, minus is not computed during runtime.

I think that Newton method is following x' = (x + c/x) / 2. You are using x' = (x - c/x) / 2 don't know why.

Looks like my code had almost as many bugs as the question.

I changed my submission to 11 iterations, which I think is necessary (see the justification in my answer). Please let me know if I went wrong with that somewhere.

@MartinBüttner, I agree. Irritating.

C, 60
I happen to use the same square root algorithm (Newton) as Peter. However, I think we need to use two different starting values in order to get away with even 8 iterations. The maximum value of b²/4-c (the normalised discriminant) is for b = -c = 1000. The minimum value is for b = 0.001; c = 0 (in fact, there are smaller values but these would be beyond the significant digits of b and c). If we split the range of values at 20, we can use 0.1 as the starting guess for the lower range and 100 as the starting guess for the upper range and always converge in 8 steps. If I could be bothered to keep searching I think I could get this down to 7, and with a few more subdivisions probably even below 6 while still saving operations (but I can't be bothered right now).
void qe(&float a, &float b, &float c)
{
    float t; // 20
    if (a)   // 21
    {
        b = b / a;  // 22
        c = c / a;  // 23
        b = b / -2; // 24
        t = b * b;  // 25
        c = t - c;  // 26
        if (c<0)    // 28
        {
            a = 0;
        }
        else
        {
            if (c<20)  // 30
                a = .1
            else
                a = 100

            t = c / a; // 31
            a = a + t; // 32
            a = a / 2; // 33

            t = c / a; // 34
            a = a + t;
            a = a / 2;

            t = c / a; // 37
            a = a + t;
            a = a / 2;

            t = c / a; // 40
            a = a + t;
            a = a / 2;

            t = c / a; // 43
            a = a + t;
            a = a / 2;

            t = c / a; // 46
            t = a + t;
            t = t / 2;

            t = c / a; // 49
            t = a + t;
            t = t / 2;

            t = c / a; // 52
            t = a + t;
            t = t / 2;

            a = 2;
            c = b + t; // 55
            b = b - t; // 56
        }
    }
    else if (b) // 57
    {
        a = 1;
        b = b / c; // 58
        b = -b;    // 59
    }
    else if (c) // 60
    {
        a = 0;
    }
    else
    {
        a = 3;
    }
}

if (c<0) scores as 2 - if and operator.

@user2992539, ah, I'm scoring that incorrectly too.

Maybe it worth find better starting value instead of huge amount of iterations.

@user2992539 good point

@user2992539 okay you can get it down to 7

@user2992539 Actually no, because c could be arbitrarily small. Even if I used a different starting value for |c| < 1, there is no starting value that works decently for 0.01 and 1e-127. Not even 11 iterations are enough for that.

@MartinBüttner Specified tighter bounds.

@user2992539 alright, I got it down to 8 iterations, and I think I could get it down a bit more, but I'll need to do that some other time.

How can you use variable t?

C# (46)
Used a different way of computing sqrt(x) (continued fractions http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Generalized_continued_fraction)
It fails for b=0 due to large rounding errors. I'm not sure how to fix that, but I hope I can help fellow contestants with a new way of doing the square roots.
Edit: Thanks to @Peter Taylor for the suggestion on how to handle b=0.
Edit 2: Thanks to @steveverrill for pointing out that there are only >2 solutions if c is also 0, thus requiring an extra if check.
       public static void doStuff(ref double a, ref double b, ref double c)
    {
        if (a == 0) //1
        {
            if (b == 0) //2
            {
                if (c == 0){ //3
                   a = 3;
                }
                else {
                   a = 0;
                }
            }
            else
            {
                b = -1 / b;//4
                b = c * b;//5
                a = 1;
            }
        }
        else
        {
            b = b / a;//6
            c = c / a;//7
            if (b == 0) //8
            {
                b = 1 + 1E-7;// still just one constant; since 0.001/1000>1E-7, b can never equal this value normally
                c = c + 0.25; //9
            }
            a = 2 * c;//10
            a = a / b;//11
            a = b - a;//12
            a = c / a; a = b - a;//14
            a = c / a; a = b - a;//16
            a = c / a; a = b - a;//18
            a = c / a; a = b - a;//20
            a = c / a; a = b - a;//22
            a = c / a; a = b - a;//24
            a = c / a; a = b - a;//26
            a = c / a; a = b - a;//28
            a = c / a; a = b - a;//30
            a = c / a; a = b - a;//32
            a = c / a; a = b - a;//34
            a = 2 / a;//35
            a = c * a;//36
            a = b - a;//37
            if (b == 1 + 1E-7) //38
            {
                b = 0;
                c = c - 0.25;//39
            }
            if (a == 0) //40
            {
                b = -1.0 / 2 * b;//41
                c = b;
                a = 2;
            }
            else
            {
                if (a < 0) //42
                {
                    a = 0;
                }
                else
                {
                    b = -1.0 / 2 * b;//43
                    a = a / 2;//44
                    c = b - a;//45
                    b = b + a;//46
                    a = 2;
                }
            }
        }
    }

I thought no one will find this method) It was the only method in my mind that uses only 3 variables without temporary.

@MartinBüttner, for a=1, b = -c = 1000, I got
a=2.0, b=0.9990019950139413, and c=-1000.9990019950139.
for a=1, b= 0.001; c = 0, I got a=2.0, b=0.0, and c=-0.001.
Since a just scales it, I don't think it matters too much here.
My real problem is when b=0 and a,c!=0.

When b=0 you should use other algorithm, or modification of continued fraction, because now there is division by zero.

b = -c / b should technically be split into two steps.

@bmarks Ah you're right, the c = 0 case is rather uninteresting. I guess the actually interesting tests would be a = 1000; b = -c = 0.001 and a = 0.001; b = -c = 1000.

@user2992539 C# can divide by 0 and not throw an error. I tried setting b to a really small nonzero number, but that didn't work too well either.

In the case b=0 the best thing to do might be to say that sqrt(0^2 - c) = sqrt(1^2 - c - 1^2) and set c = c + 1; b = 1

@PeterTaylor Maybe larger value will work better (not tested)?

C, 46 excluding handling a=0 cases, with "fast squareroot" (not "fast inverse squareroot")
I hope I've scored what I've done so far correctly. I don't know how much more I'll do on this because:

I'm not sure if casting's legal, or how to score it (the union used in another answer is more efficient, but I've not used them before.)

I'm a little unclear on the meaning of "2 equal roots are not the same as 1 root." I assume this means that a quadratic will always have either 0 o 2 real roots (which may or may not be equal) and a linear equation (a=0) will have 1 root. I would point out the only infinite case is a=b=c=0. If a=b=0 and c is nonzero, there are no roots.

Anyway, my main reason for posting is that I wanted to show that it's possible to define a "fast squareroot" (which is more suitable for the needs of this question than simply copying the famous "fast inverse squareroot" as per some other answers.) Instead of subtracting i>>1 from a constant, we add i>>1 to a constant.
The principle of the algorithm is as follows:
Assume a float is stored in an imaginary little computer as 2^AAA*1.BBBB (the 2 and 1 are not stored. AAA is known as the exponent and BBBB as the fraction.)
Performing a rightshift on the number 2^100*1.0000=16 gives 2^010*1.0000=4 which is exactly the correct square root. Repeating the process gives 2^001*1.0000=2. So far we have seen perfectly accurate results.
Now we have an odd power of 2. When we try to calculate the square root of the number 2 by rightshifting, the odd digit of the exponent underflows into the fraction and we get 2^000*1.100 which in decimal is 1.5, an error of approximately +6% on the correct value of sqrt(2)=1.414.
Moving to practical implemenations the 32-bit IEEE float (and the 64-bit, 128 bit etc.) has a bias on the exponent, so we have to add a constant to the raw shifted value. Careful choice of this constant enables the error to be limited to a range of approximately +/-3% which is a pretty good starting guess for The Newton-Raphson method. I found the constant by trial and error (there is room for some improvement, on my test cases it is more likely to give a positive error than a negative error.)
Three iterations of Newton-Raphson cleans it up very well (and may be more than necessary.)
void quad(float &a, float &b, float &c) {
  printf("a=%f b=%f c=%f",a,b,c);

  int i;                             //score 20

  c=c/a;                              // c/a
  b=b/a;
  b=b/-2;                             // -b/2a
  a=b*b;
  a=a-c;                              // (b/2a)^2-c/a), score 25

  if (a<0) a=0; else{                 // score 27

    i  = * ( int * ) &a;
    i  = i >>1;
    i  = i+0x1FB90000;
    c  = * ( float * ) &i;            //sqrt( (-b/2a)^2-c/a ) score 31

    i  = * ( long * ) &a;             //don't lose the value (b/2a)^2-c/a
    a=a/c;
    c=c+a;
    a=c/2;
    c  = * ( float * ) &i;            //second iteration
    c=c/a;
    a=a+c;
    a=a/2;
    c  = * ( float * ) &i;            //third iteration
    c=c/a;
    a=a+c;
    a=a/2;                            //score 43 after 3 iteratations

    c=b-a;                            //-b/2a in each
    b=b+a;
    a=2;                              //score 46
  }
}

C++ (29 45 44)
Note that each return can be removed, simply by using else branch.. it's just more readable. The same with if(!sth) can be simply changed using else and empty if branch....
edit: Now, with casts allowed, this answer should be correct.
void quadr(float &a, float &b, float &c) {
    b = - b;                //1
    if(!(b && c)) {         //3
        if(!a) {            //4
            a = 3;          //
            return;
        }
        a = 1;              //
        return;
    }
    if(!a) {                //5
        a = 1;              //
        b = c / b;          //6
        return;
    }

    b = b / a;              //7
    c = c / a;              //8
    c = c * 4;              //9
    a = b * b;              //10
    a = a - c;              //11
    c = a / 2;              //12

    int t = *(int*)&a;      //32
    t = t >> 1;             //33
    t = 0x5f3759df - t;     //34
    a = *(float*)&t;        //

    c = c * a;              //35
    c = c * a;              //36
    c = 1.5f - c;           //37
    a = a * c;              //38

    a = 1 / a;              //39
    if(!a) {                //40
        a = 0;              //
        return;
    }
    c = b - a;              //41
    b = b + a;              //42
    c = c / 2;              //43
    b = b / 2;              //44
    a = 2;                  //
}

I might have missed some case, feel free to prove me wrong :)

This way you are using 6 variables - 3 integers and 3 float. Change better to casts. Although cast are not allowed (as 6 vars) it will be more readable I think.

@user2992539 Casts are not allowed? I don't see that in the spec?  Or am I misunderstanding?

@user2992539: Well, I'm using 3 variables, I only treat them differently. One union still takes only 4 bytes in the memory, not 8...

@Jaa-c Maybe I misunderstood how union works. Never have used them. Let it be as it is.

@DigitalTrauma Actually I can allow casts, however I thought it's unfair because many languages doesn't support them.

@user2992539 Casts are implicit in most scripting languages.

@core1024 I mean casts like used here which allows you to get not integer part of float but it's representation in memory. Don't know languages other than C/C++ that can do that.

I don't think this meets spec: the function is supposed to take three variables which are floating point numbers, not three variables of a type you created.

Changed now with one temporary int variable...

But you're still using reinterpreting casts.

You can get rid of temp variable making casts together with computations like a = *(float*)&((*(int*)&a) >> 1);. However, it's ugly.

@MartinBüttner This answer can't be accepted, however it shows other approach and is interesting.

@user2992539: U can't use reference of an rvalue..

@Jaa-c Oh, too bad. Someone should write this in assembly)

@user2992539: Well how about current version? No reinterpret cast, only one local variable...

@Jaa-c It's ok, since I haven't specified type of temp variable.

It's still using the . structure reference operator, which isn't in the whitelist of permitted operators.

C - 50 48
I use the 32-bit float shortcut for getting a good initial seed for the square root. That allows me to get away with just a few iterations of Newton's method. I haven't found a set of coefficients yet that yield unacceptable results (outside the specified precision).
Also, I am not sure how the spec treats pointer operations. For all I know this is disallowed, but hey, I had fun!
void primitiveQuad(float *a, float *b, float *c) {
    if(0.0 == *a) { // 1
        if(0.0 != *b) { // 2
            *a = 1.0;
            *b = -1.0/(*b); // 3
            *b = (*b)*(*c); // 4
        }
        else if(*c) // 5
            *a = 0.0;
        else
            *a = 3.0;
    }
    else {
        *b = (*b)/(*a); // 6
        *c = (*c)/(*a); // 7
        *c = 4.0*(*c); // 8
        *a = (*b)*(*b); // 9
        *a = (*a) - (*c); // 10
        *c = *a; // store discriminant here for later
        if(0.0 > *a) // 11
            *a = 0.0;
        else {
            int x = *((int*)(a)); // 31
            x = x - (0x800000); // 32
            x = x >> 1; // 33
            x = x + (0x20000000); // 34
            *a = *((float*)(&x));
            {
                // add precision here through iterations

                // iteration
                x = *((int*)(a));
                *a = (*c)/(*a); // 35
                *a = *a + *((float*)(&x)); // 36
                *a = 0.5*(*a); // 37

                // iteration
                x = *((int*)(a));
                *a = (*c)/(*a); // 38
                *a = *a + *((float*)(&x)); // 39
                *a = 0.5*(*a); // 40

                // iteration
                x = *((int*)(a));
                *a = (*c)/(*a); // 41
                *a = *a + *((float*)(&x)); // 42
                *a = 0.5*(*a); // 43

            }
            *b = 0.0 - *b; // 44
            *c = *b;
            *b = *b + *a; // 45
            *c = *c - *a; // 46
            *b = 0.5*(*b); // 47
            *c = 0.5*(*c); // 48
            *a = 2.0;
        }
    }
}

Nice, but doesn't the use of x break the three variables rule ?

Oh, I thought it was just a 20-point penalty?

You're right, sorry - I didn't see that in the scoring - have an up-vote. :-)

Indirection (*) and casts are both operators and neither is in the whitelist.

I still think that language constructs that don't do any arithmetic (cast, indirection, other language-specific stuff) should be allowed... Otherwise all the answers will be mostly the same... But that's not up to me...

Question a bit updated.

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


text:
Stack Exchange Stock Exchange Tournament
Introduction
Greetings fellow traders, you have just entered the Stack Exchange stock exchange. Here you will compete to earn the money by buying and selling shares (unfortunately, we only have the single market).
Gameplay
You will need to write a program that buys and sells shares. At the start, the market price is 200, you have $10000 and no shares. Each time you buy or sell a share, the market price goes up or down.
There will be ten games played, each game with fifty rounds. At the end, the person with the highest amount of money wins.
The first game will start with at least ten entrants
Information
Your program will be supplied with three arguments:
Your bank balance
Number of shares
Market value
Round number

And you can supply one of three commands:
Name  | Command
Buy:  | b [no. shares]
Sell: | s [no. shares]
Pass: | p

For example, if you were to run the program straight:
python testprog.py 10000 0 200 1

b 100

I would suggest recording change to see if people are buying or selling shares to prevent a crash.
If you try to spend money you don't have or sell stocks that you don't have, your request will be rejected.
You are allowed to have ONE text file for recording change in stock price.
The program will be run on Ubuntu Linux.
Controller program:
# Orchestration Program

from subprocess import Popen, PIPE
import time

class Program:
     money=None
     stocks=None
     command=None

# Define class instances here
programvars = {}
# Program names here
programs = []
leaderboard = {"1": 0,
               "2": 0,
               "3": 0,
               "4": 0,
               "5": 0,
               "6": 0,
               "7": 0,
               "8": 0,
               "9": 0,
               "10": 0}
scores = []

# Programs start in a different order each time
programs = sorted(programs, key=lambda k: random.random())

f = open("stockprice.txt", "r")
f = f.split('|')
stockprice = int(f[0])
roundnum = int(f[1])
f.close()

programsfifty = programs*50

# Initialising variables
for i in programsfifty:
    #try:
    g = open(i + "properties.txt", "r")
    print(i)
    properties = g.read()
    properties = properties.split("|")

    programvars[i].money = int(properties[0])
    programvars[i].stocks = int(properties[1])
    programvars[i].command = str(properties[2])

    g.close()

    #except:
    #    pass

# Main event loop
for j in programs:
    if stockprice < 0:
        stockprice = 0

    # Example: python3 test.py [money] [stocks] [price]
    command = programvars[j].command + ' ' + str(programvars[j].money) + ' ' + str(programvars[j].stocks) + ' ' + str(stockprice) + ' ' + str(roundnum)

    out = Popen(command, shell=True, stdout=PIPE).communicate()[0].decode('utf-8')
    out = out.replace('\n', '')
    # If run on Windows
    out = out.replace('\r', '')

    if out == 'p':
        pass

    else:
        action = out.split(' ')

        if action[0] == 'b':
            # Buying shares
            if programvars[j].money - int(action[1])*stockprice > -1:
                     programvars[j].money -= int(action[1])*stockprice
                     programvars[j].stocks += int(action[1])
                     stockprice += int(action[1])

        elif action[0] == 's':
             if programvars[j].stocks - int(action[1]) > -1:
                 # Selling shares
                 programvars[j].money += int(action[1])*stockprice
                 programvars[j].stocks -= int(action[1])
                 stockprice -= int(action[1])

for k in programs:
    # Writing properties to files
    n = open(k + "properties.txt", "w")
    n.write(str(programvars[k].money)+"|"+str(programvars[k].stocks)+"|"+str(programvars[k].command))
    n.flush()
    n.close

    # Add all scores to an array for sorting
    scores.append(programvars[k].money)

scores = sorted(scores, reverse=True)
print(scores)
# Find richest program
for l in programs:
    for m in range(0, len(scores)):
        if programs.index(l) == m:
            leaderboard[programs[m]] = leaderboard.pop(str(m+1))

scorekeys = sorted(leaderboard.keys(), reverse=True)
print(scorekeys)
# Write the leaderboard
s = open("leaderboard"+str(time.localtime()[0])+"-"+str(time.localtime()[1])+"-"+str(time.localtime()[2])+".txt", "w+")

# Some problems with this, but can be worked out manually
for n in scores:
    s.write(str(scores.index(n)+1) + ": " + scorekeys[scores.index(n)] + " " + str(n) + "\n")

s.flush()
s.close()

roundnum += 1

# Write the stockprice
b = open("stockprice.txt", "w")
b.write(str(stockprice) + '|' + str(roundnum))
b.flush()
b.close()

Good luck!

"The scoring system is calculated by multiplying the amount of money you have by the number of shares you have and dividing that by zero.". So my score is always  +Inf no matter what I do?

@Philipp Ahh, that's supposed to be 200

I don't see any time loop in your program. Is each program called only once? And that in a deterministic order which depends on how you add them to the programs array at the top?

@Martin Büttner Yes, each program is called once. I'll add a random.shuffle() at the start.

The scoring system makes no sense. Surely the only reasonable way to score is money plus share value?

@BetaDecay your question has potential but it needs a lot more work before its ready for the site. Please post it on the question sandbox for more feedback: http://meta.codegolf.stackexchange.com/questions/1847/proposed-question-sandbox-mark-xiv

May I suggest substituting "traders" into "Greetings fellow businessmen"? Not everyone here is male, and it's more accurate anyway. Traders needn't have a business of their own.

@MartinBüttner you got it backwards. The last edit followed the suggestion and changed it from "businessmen" -> "traders"

@Kevin L I was just following suggestion, I see both sides of the argument

@MartinBüttner It isn't. That was my point, and the question has now been edited. Remember that "substitute into" has opposite directionality to "replace with": the original is replaced by its replacement, but a replacement is substituted into the original.

Although there are some problems with this challenge, I believe that it is salvageable. How many rounds of trading will be performed as 1 complete game? How many games will be played to determine the winning program?  Once multiple games are played, how would you determine who wins overall?

@PhiNotPi Fifty rounds (a new decision) a game will be played. There will be ten games. At the end, the person with the most money will win.

Comments can be deleted, and you can't assume that people will read them anyone. Edit the question to contain all of the necessary information (and as plain text: people shouldn't have to read through all the irrelevant I/O bits of the controller program to figure out how the market works).

Your example of input 10000 0 200 and output b 100 suggests that it's possible to spend money you don't have. What's the overdraft limit?

@Peter Taylor I was thinking of having an overdraft, but instead I set it so that if you try to spend money you don't have, it rejects your request. The same applies to selling stocks.

Someone please implement the douchebag trader whose only goal is to crash the market!

Discussion on chat suggests that if the current controller is correctly implementing the hypothetical specification, the player who goes first in the first round should always win.

@Peter Taylor Hmmm... Would randomising values help?

May I suggest adding a 4th input to the player programs, the number of rounds already played. Or the current round number.

@AndoDaan Would that help?

@BetaDecay Well, I just wrote a random bot, but I would like to nuance him with not being able to spend more than half his balance before the first 25 rounds. And then him acting more frantic in the last 10 or 5 rounds. I could do this with file save option, but it's a hassle.

@AndoDaan Okay, I'll add it

Read title as "Stack Exchange sock exchange"

@programmer5000 That would be an awesome challenge :D

Short-Sighted Seller - Perl
This bot has the simple strategy of maximizing its score at the end of every trading opportunity.  It acts as if every round were the last round.
($money,$stocks,$price) = @ARGV;
$value = $money + $stocks * $price;
if($price > 0){
 $optimal = $value / (2 * $price);
}
else{
 $optimal = 9x15 + $stocks; #suitably large number
}
$rounded = int($optimal + 0.5);
$delta = $rounded - $stocks;
if($delta > 0){
 print "b $delta";
}
elsif($delta < 0){
 $delta *= -1;
 print "s $delta";
}
elsif($delta == 0){
 print "p";
}

You can run it like so:
perl shortsightedseller.plx [money] [stocks] [price]


text:
DNA: Deoxyribonucleic ASCII
Given a sequence of the bases Adenine, Cytosine, Guanine and Thymine (encoded as ACGT), you're to produce an ASCII art representation of a corresponding double strand of DNA.
The strand will extend vertically. The left-hand strand is the one you are given as input. The right-hand strand will be its complement. For those not familiar with DNA, A is paired with T and C is paired with G. Furthermore, there is backbone structure on either side of the double strand which is identical for all bases. So if you were given the input TAGCAT the large-scale structure of the ASCII art would be:
BTAB
BATB
BGCB
BCGB
BATB
BTAB

where B represents the backbone. Now each of these letters stands for an entire molecule and you're to reproduce the actual molecular structure.
The Bases
Use the following templates1 for each of the bases (each one is displayed together with its complementary base and the two backbone molecules):
1Credits to Peter Taylor for helping out with the ASCII layout.
Adenine
 O    O
  \\ /
    P
   / \
--O   O
     /                                         |
    <            N      NH2 ..... O      *     |
     \         // \    /           \\   /      |
      +--O    //   ----             ----       |
      |   \   |   //  \\           /   \\      |
      |    >--N--<      N ...... HN      >  ---+
      |   /       \    /           \    /  /   |
      +---         N===             ---N--<    |
      |                            //      \   |
      |                           O         O--+
      |                                         \
      |                                          >
      |                                         /
                                               O   O--
                                                \ /
                                                 P
                                                / \\
                                               O    O

Cytosine
 O    O
  \\ /
    P
   / \
--O   O            NH2 ..... O      N
     /            /           \\   / \\        |
    <         ----             ----   \\    ---+
     \       //  \\           /   \\   |   /   |
      +--O  <      N ...... HN      >--N--<    |
      |   \  \    /           \    /       \   |
      |    >--N---             ===N         O--+
      |   /      \\           /                 \
      +---         O ..... H2N                   >
      |                                         /
                                               O   O--
                                                \ /
                                                 P
                                                / \\
                                               O    O

Guanine
 O    O
  \\ /
    P
   / \
--O   O
     /                                         |
    <            N      O ..... H2N            |
     \         // \   //           \           |
      +--O    //   ----             ----       |
      |   \   |   //   \           //  \\      |
      |    >--N--<      NH ...... N      >  ---+
      |   /       \    /           \    /  /   |
      +---         N===             ---N--<    |
      |                \           //      \   |
      |                 NH2 ..... O         O--+
      |                                         \
      |                                          >
      |                                         /
                                               O   O--
                                                \ /
                                                 P
                                                / \\
                                               O    O

Thymine
 O    O
  \\ /
    P
   / \
--O   O     *      O ..... H2N      N
     /       \   //           \    / \\        |
    <         ----             ----   \\    ---+
     \       //   \           //  \\   |   /   |
      +--O  <      NH ...... N      >--N--<    |
      |   \  \    /           \    /       \   |
      |    >--N---             ===N         O--+
      |   /      \\                             \
      +---         O                             >
      |                                         /
                                               O   O--
                                                \ /
                                                 P
                                                / \\
                                               O    O

Constructing the Double Strand
These repeat vertically, such that there are no gaps in the backbone structure. This means that the bounding boxes of these four templates will overlap.
The bottom end of the left and top end of the right backbone will connect to the O of an OH.
The free O at the top end of the left and bottom end of the right backbone will have a free bond going inwards, indicated by --.
Example ATG
 O    O--
  \\ /
    P
   / \
--O   O                                        OH
     /                                         |
    <            N      NH2 ..... O      *     |
     \         // \    /           \\   /      |
      +--O    //   ----             ----       |
      |   \   |   //  \\           /   \\      |
      |    >--N--<      N ...... HN      >  ---+
      |   /       \    /           \    /  /   |
      +---         N===             ---N--<    |
      |                            //      \   |
      |                           O         O--+
      |                                         \
      |                                          >
      |                                         /
 O    O                                        O   O--
  \\ /                                          \ /
    P                                            P
   / \                                          / \\
--O   O     *      O ..... H2N      N          O    O
     /       \   //           \    / \\        |
    <         ----             ----   \\    ---+
     \       //   \           //  \\   |   /   |
      +--O  <      NH ...... N      >--N--<    |
      |   \  \    /           \    /       \   |
      |    >--N---             ===N         O--+
      |   /      \\                             \
      +---         O                             >
      |                                         /
 O    O                                        O   O--
  \\ /                                          \ /
    P                                            P
   / \                                          / \\
--O   O                                        O    O
     /                                         |
    <            N      O ..... H2N            |
     \         // \   //           \           |
      +--O    //   ----             ----       |
      |   \   |   //   \           //  \\      |
      |    >--N--<      NH ...... N      >  ---+
      |   /       \    /           \    /  /   |
      +---         N===             ---N--<    |
      |                \           //      \   |
      |                 NH2 ..... O         O--+
      |                                         \
      |                                          >
      |                                         /
      OH                                       O   O--
                                                \ /
                                                 P
                                                / \\
                                             --O    O

More Examples:
Here are the MD5 hashes of several more examples (without extraneous leading or trailing spaces):
ATG      2e4a906c44a96fe84134bf4346adf11c (this is the above example)
C        e3648b8960967463784818c3eee57246
TTT      6028a90b05775905ef1a00e7a45463c5
TAGCAT   3b834d2b7b9adc4113ffabd52d354c41
GATTACA  a19463f965c641d071e07da59d64a418

Let me know if you think any of these are wrong.
If you're unsure how to check your results' hashes reliably, try this online MD5 generator. Make sure that there is no trailing line break.
Further Notes
You may use leading or trailing spaces as you see fit. Of course, if you use leading spaces it has to be the same amount in each line.
If I have made any mistakes in copying the chemical structure, the above templates are still normative for the purposes of this challenge.
You may write a function or a program which takes the input string as a parameter, command-line argument via STDIN or expects it to be stored in a variable. Write the resulting ASCII art to STDOUT.
This is code golf, so the shortest answer (in bytes) wins.

Amazing challenge!

GATTACA should be required

@Kevin I even thought about that before, so I added it now. ;) I also fixed the hash for TTT because the string contained a trailing newline.

How do you get the md5 checksum ? I copied your ATG output and got different checksum. And different OS will get different checksums. You can try these with unix2dos, unix2mac....

@Ray I got them using Ruby's Digest::MD5.hexdigest() with Unix-style line endings. Also, none of them have a trailing new line. Paste it here - this online MD5 generator agrees with my hashes.

Oh, I see. I used xsel -b | md5sum and this will have a trailling \n.

This is my favorite code golf ever.

Gattaca... love that movie.  Did not realize until just now about GATTACA. o_o Mind blown.

Perl 5 (510)
Perl's fine with null bytes, so please use the hexdump provided for running this.
This works by printing out different parts of the DNA strand, with parts being one or more lines. An O or H is appended to the top line of each component to ensure valid output.
Assumes input is in the variable $_.
Golfed version:

use Compress::Zlib;@f=(eval uncompress q+xœÍUËnÃ ¼ó{³””¬”slqäù |xšÅ<
MÔv¤(1b¼;Ì„]8× `?CÐË×ÂÜ/¥Àîº¤Â—¼ÃÍ"6p!ÇvDÿ@k
‘®^ÝÀ
²>ÈB$ì¡ÌHBýi`ã\qþˆRn^‚¢6WéJ±íRCXÀ\Cj[ëzÖKg-µ€˜*Rt®abš3‘ª¤°È†"]ÖSX‰G2ôœÂV<<#9_ÐŽG´8Oa3uE'ÇC%…¹—tLºšÂBCQ‹¡NÈ»*/
V×AÛVÔÖAr©KûÊhát°DÃÁZÿÁ>;       kM‚2(9áýIP
t'A”¿žg
q= Š[~yÌ²ùNÇsNsŽŽG×œ:IÏqŠÙl)˜ùð
ì…çÎÁ«:eôu?<(-  é æ ŽRxNSÜAM1Â• —)š—%+);s/./$y.=$f[$u?8:9].$f[$q=(-65+ord$&)%15].($u++?"    O":H).$f[$q+1]/ge;($y.=$f[10])=~s/@/\\/g;print$y

Ungolfed version:

use Compress::Zlib;
# load parts to @f; see below for list of parts
@f=(eval uncompress q+ .... +);
# for each chracater in input ($_)
s/./
    # append either the one or two backbone molecules
    # then append most of the first line of the base, followed by an O or H
    # then append the rest of the base
    $y .= $f[$u?8:9] . $f[$q = (-65+ord$&)%15] . ($u++?"    O":H) . $f[$q+1]
/ge;
# append the last backbone molecule, then replace
#  @ with \
($y .= $f[10])=~s/@/\\/g;
print $y

(-65+ord$&)%15 conveniently results in A=>0, C=>2, T=>4, G=>6, which is perfect as the program needs two elements in the array for each letter.
The center part, top part, and bottom part are stored in indices 8-10 in that order.
List of Parts (uses @ instead of \ to avoid a ton of escaping):
'--O   O                                        O',
'
     /                                         |
    <            N      NH2 ..... O      *     |
     @         // @    /           @@   /      |
      +--O    //   ----             ----       |
      |   @   |   //  @@           /   @@      |
      |    >--N--<      N ...... HN      >  ---+
      |   /       @    /           @    /  /   |
      +---         N===             ---N--<    |
      |                            //      @   |
      |                           O         O--+
      |                                         @
      |                                          >
',
'--O   O            NH2 ..... O      N          O',
'
     /            /           @@   / @@        |
    <         ----             ----   @@    ---+
     @       //  @@           /   @@   |   /   |
      +--O  <      N ...... HN      >--N--<    |
      |   @  @    /           @    /       @   |
      |    >--N---             ===N         O--+
      |   /      @@           /                 @
      +---         O ..... H2N                   >
',
'--O   O     *      O ..... H2N      N          O',
'
     /       @   //           @    / @@        |
    <         ----             ----   @@    ---+
     @       //   @           //  @@   |   /   |
      +--O  <      NH ...... N      >--N--<    |
      |   @  @    /           @    /       @   |
      |    >--N---             ===N         O--+
      |   /      @@                             @
      +---         O                             >
',
'--O   O                                        O',
'
     /                                         |
    <            N      O ..... H2N            |
     @         // @   //           @           |
      +--O    //   ----             ----       |
      |   @   |   //   @           //  @@      |
      |    >--N--<      NH ...... N      >  ---+
      |   /       @    /           @    /  /   |
      +---         N===             ---N--<    |
      |                @           //      @   |
      |                 NH2 ..... O         O--+
      |                                         @
      |                                          >
',
'      |                                         /
 O    O                                        O   O--
  @@ /                                          @ /
    P                                            P
   / @                                          / @@
',
' O    O--
  @@ /
    P
   / @
',
'      |                                         /
      OH                                       O   O--
                                                @ /
                                                 P
                                                / @@
                                             --O    O'

Hexdump:
0000000 7375 2065 6f43 706d 6572 7373 3a3a 6c5a
0000010 6269 403b 3d66 6528 6176 206c 6e75 6f63
0000020 706d 6572 7373 7120 782b cd9c cb55 c36e
0000030 1020 f3bc 7b15 94b3 ac94 7394 716c 04e4
0000040 20f9 7c7f 9a78 3cc5 4d0a 76d4 28a4 6231
0000050 3bbc 84cc 385d 00d7 3f60 d043 d7cb dcc2
0000060 1c2f c0a5 08ee ba0f c2a4 bc97 cdc3 3622
0000070 2170 1004 76c7 ff44 6b40 910a 0216 ae01
0000080 8d5e 0fdd 0dc0 3eb2 42c8 ec24 cca1 481e
0000090 9042 08fd 8169 6012 5ce3 fe71 5288 5e6e
00000a0 0c82 36a2 e957 084a edb1 4352 c058 435c
00000b0 5b6a ebad d67a 4b10 2d67 80b5 2a98 108d
00000c0 1052 ae74 0c61 9a62 1b01 9133 a4aa c8b0
00000d0 2286 d65d 5853 4789 f432 c29c 3c56 233c
00000e0 1839 d05f 478e 38b4 614f 1e33 0775 2745
00000f0 c71e 2543 b985 1306 7497 ba4c c29a 4342
0000100 510e a18b 4e0e bbc8 082a 0715 0d2f d756
0000110 db41 5616 7fd4 41d6 a972 4b10 0efb 68ca
0000120 7fe1 b074 c344 1ec1 ff5a 1ec1 3b3e 1a09
0000130 6b09 824d 2832 e139 49fd 0f50 740a 4127
0000140 9411 9ebf 6704 710d 3dad 8a09 175b 797e
0000150 cc12 90b2 4ef9 73c7 4e0b 7311 8e8e d747
0000160 1b9c 493a 71cf d98a 296c f998 0df0 85ec
0000170 cee7 abc1 1a3a f465 3f75 283c 2d07 0907
0000180 a0e9 20e6 528e 7813 534e 41dc 314d 95c2
0000190 97a0 2917 979a 2b25 3b29 2f73 2f2e 7924
00001a0 3d2e 6624 245b 3f75 3a38 5d39 242e 5b66
00001b0 7124 283d 362d 2b35 726f 2464 2926 3125
00001c0 5d35 282e 7524 2b2b 223f 2020 2020 224f
00001d0 483a 2e29 6624 245b 2b71 5d31 672f 3b65
00001e0 2428 2e79 243d 5b66 3031 295d 7e3d 2f73
00001f0 2f40 5c5c 672f 703b 6972 746e 7924
00001fe

Can you just replace all the back slashes with the escaped version in one go? It's hard to judge the output when it is full of @.

@githubphagocyte s/@/\\/g does exactly that, prior to printing. The list of parts is merely present to show what the compressed data is.

Python 3, 1008 bytes
Decomposite to smaller blocks and then compress using python's zlib and encode the binary data with asii85 encoding. Before compressing, the size is 629 and after compression and encoding, the size is 260.
Smaller blocks:
    N      NH2            NH2 ...   *      O .....      N      O ..     O    O              ---+
  // \    /              /           \   //           // \   //          \\ /              /   |
 //   ----           ----             ----           //   ----             P            --<    |
 |   //  \\         //  \\           //   \          |   //   \           / \              \   |
 N--<      N ..    <      N .....   <      NH ....   N--<      NH .    --O   O              O--+
     \    /         \    /           \    /              \    /             /                   \
      N===           N---             N---                N===             <                     >
                        \\               \\                   \             \                   /
                          O .....          O                   NH2           +--O              O   O--
                                                                             |   \              \ /
                                                                             |    >--            P
                                                                             |   /              / \\
                                                                             +---              O    O

The program reads from STDIN. It may have trailing spaces at the end of each line and may have empty lines at the end.
import zlib,base64
D=input()
B=b'GasbU3tfFR$q,H5@dA9CAl@Bd?/ZcRUN$!!66MJ3&IN+RbL6[r)7K,3-8;3.^a\'7XZD_Lh;(7`.g>%[1,o(<9L\\neaPK"9^lCg7teknAd\\HXFNbL!)l/pG]YNpRS-C]sXR5A[A[#C&pnT;I-Q$Bj@n$L"ODZk8M_YcM#\\5PaLq3@UfJmfm[)$+#H,A\\B+b`mL9^OQ/cET-@`YRD_DJ6mXMD">9HHep\\%LnL8&\\G?fDdbs20%[J\'jMG[Qp'
B=[b.split('\n')for b in zlib.decompress(base64.a85decode(B)).decode().split('\n\n')]
C=dict(zip('/\\<>', '\\/><'))
a=[(6,14),(6,28),(10,40)]
b=[(4,12),(4,26),(6,40)]
P=[a,b,b,a]
H=[18,14,14,18]
J=''.join
R=range
L=len
F=[[' ']*54 for _ in R(5+18*L(D))]
e=enumerate
y=0
def t(b,p):
 for i,r in e(b):
  for j,c in e(r):
   if' '!=c:F[y+p[0]+i][p[1]+j]=c
O=['OH']
U=['--']
t(O,(4,47))
t(U,(0,7))
for i in map('ACTG'.index,D):
 a,b,c=P[i];t(B[4],(0,0));t(B[i],a);q=B[(i+2)%4];t([J(C.get(z,z)for z in l[::-1]).replace('2HN', 'H2N')for l in[r+' '*(max(map(L,q))-L(r))for r in q]],b);t(B[5],c)
 for j in R(y+13,y+H[i]):F[j][6]='|'
 for j in R(y+5,y+c[0]):F[j][47]='|'
 y+=H[i]
t(O,(0,6))
t(U,(4,45))
for l in F:print(J(l))

Checksum matched using this script
And here's the ungolfed version:
import zlib, base64

flip_char_map = dict(zip('/\\<>', '\\/><'))

def flip_char(c):
    return flip_char_map.get(c, c)

def pad(block):
    w = max(map(len, block))
    return [line + ' ' * (w - len(line)) for line in block]

def flip(block):
    return [''.join(map(flip_char, line[::-1])).replace('2HN', 'H2N') for line in pad(block)]

blocks = b'GasbU3tfFR$q,H5@dA9CAl@Bd?/ZcRUN$!!66MJ3&IN+RbL6[r)7K,3-8;3.^a\'7XZD_Lh;(7`.g>%[1,o(<9L\\neaPK"9^lCg7teknAd\\HXFNbL!)l/pG]YNpRS-C]sXR5A[A[#C&pnT;I-Q$Bj@n$L"ODZk8M_YcM#\\5PaLq3@UfJmfm[)$+#H,A\\B+b`mL9^OQ/cET-@`YRD_DJ6mXMD">9HHep\\%LnL8&\\G?fDdbs20%[J\'jMG[Qp'
blocks = [b.split('\n') for b in zlib.decompress(base64.a85decode(blocks)).decode().split('\n\n')]

poss = [
    [(6, 14), (6, 28), (10, 40)],
    [(4, 12), (4, 26), (6, 40)],
    [(4, 12), (4, 26), (6, 40)],
    [(6, 14), (6, 28), (10, 40)],
]

heights = [18, 14, 14, 18]

get_id = 'ACTG'.index
dna = input()
height = sum(heights[get_id(x)] for x in dna)
field = [[' '] * 54 for _ in range(height + 5)]

def put(block, pos):
    i, j = pos
    for di, row in enumerate(block):
        for dj, c in enumerate(row):
            if c != ' ': field[y + i + di][j + dj] = c

y = 0
put(['OH'], (4, 47))
put(['--'], (0, 7))
for p in dna:
    i = get_id(p)
    h = heights[i]
    pos = poss[i]
    put(blocks[4], (0, 0))
    put(blocks[i], pos[0])
    put(flip(blocks[(i + 2) % 4]), pos[1])
    put(blocks[5], pos[2])
    for j in range(y + 13, y + h):
        field[j][6] = '|'
    for j in range(y + 5, y + pos[2][0]):
        field[j][47] = '|'
    y += h
put(['OH'], (0, 6))
put(['--'], (4, 45))

for line in field: print(''.join(line).rstrip())

from hashlib import md5
import sys
result = '\n'.join(map(str.rstrip, map(''.join, field))).encode()
print(md5(result).hexdigest(), file=sys.stderr)

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


text:
Expression that equals its length
Given a number, find an expression in words equaling that number, with a length of that number.
Thus, to an input of 15, you might output sixteen minus one, which has fifteen characters (not counting spaces). If multiple solutions exist, print whichever you want. If none exist, print impossible
Use only the operators plus, minus, times, and divided by. Operators are evalutated left to right.
Format 1234 as one thousand two hundred thirty four. Note the absence of "and", and that there are no dashes or commas.
The input and all numbers used in the output must be positive integers less than 10,000.
The input will be given as a command line argument. Print to standard output.
Examples
1: impossible
4: four
7: impossible
13: eight plus five (you could also output "five plus eight")
18: one plus two times six (note that operators are evaluated from left to right)
25: one thousand divided by forty

nonnegative integers? So for 1234 we can do (massive expression) times zero plus one thousand two hundred thirty four. You may want to exclude zero. Up to you.

@steveverrill Good point; I've changed it to "positive integers".

sooo...one hundred three times one times one times one times one times one times one times one times one times one times one times one is valid?

@Qwix Yes; boring answers are acceptable, although that one doesn't work for 104, 105, 106, 107, 108, 109, 110, or 111.

Javascript, 434 characters
function f(s){return s.replace(/[A-Z]/g,function(t){return{O:'one',T:'two',H:'three',F:'four',I:'five',S:'six',E:'seven',G:'eight',N:'nine',Z:'ten',P:' plus ',M:' minus ',U:' times ',X:'teen',A:'thir',B:'twenty'}[t]})}A='TPAX|GeenMT|EXUO|B FMS|F|GPSUT|ZPHPG|BPFMT|AXPFPS|BPGMF|EUOPGeen|NPT|B GMSPI|GPI|EPE'.split('|');O=26640;function S(n){return n<15&&!(O>>n&1)?'Invalid':f(A[v=n%15])+(new Array(~~(n/15)+(O>>v&1))).join(f('PSPN'))}

Yields a function in the global namespace, S, that accepts any non-negative integer and returns the required string, or "Invalid" if the integer cannot be represented within the specifications.
I would appear to have used the same approach as @optokopper, having made the same observation that "plus six plus nine" is the shortest possible padding string, and that all numbers greater than 27 can be expressed by concatenating one of 15 base strings to repeated copies of the pad.
Having said that, the tables of base strings we use differ, and my solution relies on bit twiddling and the remainder operator (%). It also includes "multiplied by" as a possible operation. And naturally the mechanics of how the strings are constructed are completely different due to the dissimilarity between C and Javascript.
That's my best attempt, at any rate. ;)
Special thanks to @chiru, whose discussion of which numbers were achievable helped prevent fruitless searching.

JS, 1719/1694
Theory
Unfortunately, the rule set that you provide may not be a wise decision from a mathematical point of view. In fact, using a smaller subset of rules, you can find a solution for every number in the given interval

except for

for which there is no solution.
Reduced rule set
Consider the following subet of rules:

Use only the operators plus, minus and times.
You don't need to implement multiple occurrences of plus or minus in your expressions.
You don't need to implement neither division nor operator associativity (as their solution set is already covered by the first rule).

The reason why this works is that, as you discussed earlier with @Qwix, you allow boring answers, that is, expressions that end in the regular expression
( times one)+$. Allowing this, each number in the given interval will have a solution.
When you replied in one of your comments,

@Qwix Yes; boring answers are acceptable, although that one doesn't
  work for 104, 105, 106, 107, 108, 109, 110, or 111. –

you were absolutely right: This does not work when you're trying to build your expression starting with the numbers themselves, i.e. one hundred four times one times one … or any other of those numbers.
If however, your expression starts with an expression whose evaluation equals one of the given numbers, you're out of luck. For example, note that 17 + 87 is indeed 104, so we could write 104 as:
104: seventeen plus eighty seven times one times one times one times one times one times one times one times one times one times one

To see that this subset works, save this file as num.js and make sure that SpiderMonkey, a JavaScript engine for command lines, is installed on your system.
The algorithm

Let us define the property K for positive integers as the state of the number having N letters and having a value of N.
Let us further define the property F for an expression as the state of its word conversion being 8k-times shorter than its evaluation with k ∈ ℕ. F stands for "fillable" and describes whether or not we can fill the word conversion of the expression with expressions of length 8 (i.e. " times one") such that the resulting expression might get the property N.

We then proceed as follows:

Convert the input number to words.
Check if the input number has property K.

If it does, return the words (4 is the only number with this property, unfortunately).
If it doesn't, proceed.

For all two-operand expressions (additions, subtractions and multiplications in this order) that result in the input number, check if their evaluation has property K.

If it does, return the words.
If it doesn't, check if the two-operand expression has property N.

If it does, fill the expression with " times one" and check if the evaluation of the resulting expression has property K.

If it does, return the words
If it doesn't, proceed

If it doesn't, proceed

Go drink a coffee

Practice
num.js (for SpiderMonkey / command lines)
function X(e,t){return e+": "+t}function P(e){var n,t;for(n=1;.5*e+(e%2===0?1:0)>n;++n){if(t=C.s(n)+" plus "+C.s(e-n),t.replace(/\s/g,"").length===e)return t;if(F(e,t)&&e>t.length)return G(e,t)}return!1}function M(e){var t,n;for(t=L;t>1;--t){if(0>t-e)return!1;if(n=C.s(t)+" minus "+C.s(t-e),n.replace(/\s/g,"").length===e)return n;if(F(e,n)&&e>n.length)return G(e,n)}return!1}function F(e,t){return(e-t.replace(/\s/g,"").length)%8===0}function G(r,t){var e,i=(r-t.replace(/\s/g,"").length)/8,n="";for(e=0;i>e;++e)n+=" times one";return t+n}function T(e){var t,n,r;if(F(e,C.s(e)))return G(e,C.s(e));for(t=1,n=1;t<Math.floor(Math.sqrt(e));++t){for(;e>tn;)++n;if(tn===e&&(r=C.s(t)+" times "+C.s(n),r.replace(/\s/g,"").length===e))return r}return!1}function Y(e){var n,r,t;return e===C.s(e).length?X(e,C.s(e)):(n=P(e))?X(e,n):(r=M(e))?X(e,r):(t=T(e),t?X(e,t):X(e,"impossible"))}var L=1e4,C=new function(){return this.o=["","one","two","three","four","five","six","seven","eight","nine"],this.t=["","","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"],this.T=["ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"],this.s=function(e){return e?this.m(e):"zero"},this.m=function(e){return e>=1e6?this.m(Math.floor(e/1e6))+" million"+(e%1e6!==0?" "+this.Z(e%1e6):""):this.Z(e)},this.Z=function(e){return e>=1e3?this.h(Math.floor(e/1e3))+" thousand"+(e%1e3!==0?" "+this.h(e%1e3):""):this.h(e)},this.h=function(e){return e>99?this.o[Math.floor(e/100)]+" hundred"+(e%100!==0?" "+this.U(e%100):""):this.U(e)},this.U=function(e){return 10>e?this.o[e]:e>=10&&20>e?this.T[e-10]:this.t[Math.floor(e/10)]+(e%10!==0?" "+this.o[e%10]:"")},this};print(Y(0|arguments[0]))
num.js (for browsers)
The given code from above can't work for browsers due to its last command, which grabs the command line arguments in order to make a nice command out of the given script.
In order to run the JavaScript code directly from within your browser, select this piece of the above code:

function X(e,t){return e+": "+t}function P(e){var n,t;for(n=1;.5*e+(e%2===0?1:0)>n;++n){if(t=C.s(n)+" plus "+C.s(e-n),t.replace(/\s/g,"").length===e)return t;if(F(e,t)&&e>t.length)return G(e,t)}return!1}function M(e){var t,n;for(t=L;t>1;--t){if(0>t-e)return!1;if(n=C.s(t)+" minus "+C.s(t-e),n.replace(/\s/g,"").length===e)return n;if(F(e,n)&&e>n.length)return G(e,n)}return!1}function F(e,t){return(e-t.replace(/\s/g,"").length)%8===0}function G(r,t){var e,i=(r-t.replace(/\s/g,"").length)/8,n="";for(e=0;i>e;++e)n+=" times one";return t+n}function T(e){var t,n,r;if(F(e,C.s(e)))return G(e,C.s(e));for(t=1,n=1;t<Math.floor(Math.sqrt(e));++t){for(;e>tn;)++n;if(tn===e&&(r=C.s(t)+" times "+C.s(n),r.replace(/\s/g,"").length===e))return r}return!1}function Y(e){var n,r,t;return e===C.s(e).length?X(e,C.s(e)):(n=P(e))?X(e,n):(r=M(e))?X(e,r):(t=T(e),t?X(e,t):X(e,"impossible"))}var L=1e4,C=new function(){return this.o=["","one","two","three","four","five","six","seven","eight","nine"],this.t=["","","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"],this.T=["ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"],this.s=function(e){return e?this.m(e):"zero"},this.m=function(e){return e>=1e6?this.m(Math.floor(e/1e6))+" million"+(e%1e6!==0?" "+this.Z(e%1e6):""):this.Z(e)},this.Z=function(e){return e>=1e3?this.h(Math.floor(e/1e3))+" thousand"+(e%1e3!==0?" "+this.h(e%1e3):""):this.h(e)},this.h=function(e){return e>99?this.o[Math.floor(e/100)]+" hundred"+(e%100!==0?" "+this.U(e%100):""):this.U(e)},this.U=function(e){return 10>e?this.o[e]:e>=10&&20>e?this.T[e-10]:this.t[Math.floor(e/10)]+(e%10!==0?" "+this.o[e%10]:"")},this}
Now, paste it into your browser's JavaScript console, so you can produce the same results from within your browser with, for example:

Y(1234);

Examples (command line)
chiru@chiru ~ $ js num.js 28
28: fourteen plus fourteen times one
chiru@chiru ~ $ js num.js 7
7: impossible
chiru@chiru ~ $ js num.js 42
42: nine thousand sixty minus nine thousand eighteen

And in order to see the trick with which you can make each number work, just have a look at the boring answer for js num.js 1337:
1337: ten plus one thousand three hundred twenty seven times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one times one
The provided codes generates valid solutions for the given interval (and probably even above, you'd only have to raise the value of the variable L).
Statistics
I was interested in "how boring" the expressions were (or: how much the substring times one was used per expression within this algorithm), as this part was responsible for finding a solution for every number within the given interval. See for yourselves:
x: n-th expression (min. 0, max. 10,000)
y: number of occurences of substring " times one" within expression (min. 0, max. 1245)

Conclusions:

The expressions tend to get more and more boring in a linear manner.
Over 99% of solutions are boring.

A solution for 4 exists—four

@FUZxxl I never denied that. In case you're responding to If it does, return the words (4 is the only number with this property, unfortunately), you might have misunderstood this section. It says that 4 is the only operator-free expression that forms its own solution.

@FUZxxl Oh, okay. I just spotted that in the beginning section, I said that there are no solutions in X = [0; 10] ∪ {12}, although later, I say that 4 has a solution. I corrected the interval, thanks. :)

C, 450 characters
Edit: removed zero
Edit: using only plus and minus
I searched for the shortest expression that adds chars and keeps the condition true.
I found plus ten plus five is 15 long and adds 15 to the string.
I need only expressions for the first 15 numbers that are not impossible, to express any possible number.
12 is the biggest impossible number, therefore it suffices to hardcode numbers smaller 28.
4 = four
11 = six plus five
13 = eight plus five
14 = twenty minus six
15 = twenty minus five
16 = eighteen minus two
17 = fourteen plus three
18 = twenty two minus four
20 = thirty two minus twelve
21 = twenty plus two minus one
22 = twenty plus four minus two
23 = thirty minus eight plus one
24 = twenty plus eight minus four
25 = twenty plus eight minus three
27 = twenty eight minus six plus five
We can write every number >27 as x*15 + one of the numbers above.
Golfed
#define P" plus "
#define M" minus "
#define U"four"
#define F"five"
#define E"eight"
#define W"twenty"
#define A"ten"P F P
*e[]={0,0,0,0,U,0,0,0,0,0,0,F P"six",0,E P F,W M"six",W M F,E"een"M"two",U"teen"P"three",W" two"M U,A U,"thirty two"M"twelve",W P"two"M"one",W M"two"P U,"thirty"P"one"M E,W P E M U,W M"three"P E,A F P"six",W" "E M"six"P F};main(n){n=atoi(1[(int*)1[&n]]);for(printf("%d: ",n);n>27;n-=15)printf(A);puts(e[n]?e[n]:"impossible");}

Readable Code
#include <stdio.h>
#include <stdlib.h>

// add fifteen to string, both as value and as character count (without spaces)
const char *add_fifteen = "plus ten plus five";

// table with hardcoded expressions
// NOTE: we could calculate 19, 26, 28 and 29 from 4, 11, 13 and 14
// but we would need more logic, so we hardcode those 4 numbers too.
const char *expressions[30]={"impossible", "impossible", "impossible", "impossible",
    "four", "impossible", "impossible", "impossible", "impossible",
    "impossible", "impossible", "five plus six", "impossible",
    "eight plus five", "twenty minus six",
    "fourteen plus one", "eighteen minus two", "fourteen plus three",
    "twenty two minus four", "four plus ten plus five",
    "thirty two minus twelve", "nine plus seven plus five",
    "twenty plus four minus two", "twelve plus seven plus four",
    "twenty plus eight minus four", "twenty plus eight minus three",
    "five plus six plus ten plus five", "twenty eight minus six plus five",
    "eight plus five plus ten plus five", "seven plus seven plus ten plus five"};

int main(int argc,char *argv[])
{
    int n = strtol(argv[1], NULL, 0);
    int fifteens = 0;

    printf("%d: ", n);

    // how many times do we need to add fifteen?
    if(n>29){
        fifteens=(n/15) - 1;
        n -= fifteens*15; // ensure 30 > n >= 15, so we don't get "impossible"
    }

    // look up the expression for n
    printf("%s", expressions[n]);

    // add fifteens till we are done
    while(fifteens-- > 0) {
        printf(" %s", add_fifteen);
    }

    printf("\n");
    return 0;
}

Not quite sure how your code works, but since the question states that all numbers used in the output must be positive integers, could you remove the #define Z "zero" from your code along with instances of Z since you shouldn't ever use it?

" plus twelve" is 12 letters. Would that help shorten your code?

I would make it shorter, alas spaces dont count, plus twelve is only 10 letters

OK, I misread the rules.


text:
Print all multiples of 32 from 0 to `n`...imperfectly
Objective: Print all multiples of 32 from 0 to an arbitrary number n.
Rules:

One argument will be given: a single integer from 0 to 231 - 1. This will be n here on out.
The first iteration must be 0, and the last iteration must be n. 0 is to be counted as a multiple of 32.
Each time a multiple is encountered, the multiple itself must be printed with no leading whitespace, and then it must be immediately followed by a newline (CR, CRLF, and LF are all acceptable as long as they are consistent.
A bug must be introduced such that a minimum of n+1 floor 32 cases are incorrectly printed/omitted (in the average case).

Perfection is allowed for n less than or equal to 32.

Your source code must be in pure ASCII. Exceptions only include APL and others that use non-ASCII operators.
This is an underhanded contest. The best code is clear, concise, obvious, and wrong.

Example in C++ (except for clear bug):
// This conforms to the rules, but is a bad entry.
#include <iostream>
#include <cstdlib>
#include <cstdint>

int main(int argc, char* argv[]) {
  int32_t max = (int32_t) atol(argv[1]);
  int32_t i = 0;
  while (i != max) {
    if (!(i % 32) && !((int) (4 * random()) / 4)) {
      cout << i << endl;
    }
    i++;
  }
  return 0;
}

Most popular answer wins, so make it good!

"it must match the following regex" -- is multiline mode on?

@JanDvorak It matches the whole, not per line. I forget which is multiline.

floored division is normally denoted by div.

Is the program supposed to find multiples of 32 or 42? The title says 42, but you said 0 is to be counted as a multiple of 32.

@Cameron Fixed.

Well the title still says 32 while in the objective it is state as 42, so what now?

I really shouldn't program.

Does printing nothing work? I have an idea, but I'm not sure if that would omit more numbers than the maximum.

@KSFT Actually, since it is a popularity contest, I'm going to modify that rule.

Why do you prohibit certain characters in the program source?

I'll clarify it as ASCII. It's poorly worded

I'm voting to close this question as off-topic because it's an [underhanded] challenge, which was on-topic a year ago, but is now off-topic by community consensus.

C
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
    int n = atoi(argv[1]);
    for(int i = 0; i < n; i++) {
        if(i & 31 == 0) {
            printf("%d\n", i);
        }
    }
}

@Jakube: It does give 2 wrong results for n=63.  It doesn't print 0 and 32 when it should.

modified from the example.
#include <iostream>
#include <cstdlib>
#include <cstdint>

using namespace std;

int main(int argc, char* argv[]) {
  int32_t n = (int32_t) atol(argv[1]);
  int32_t i = 0;

  while (i != n) {
    if (!(i % 32) && n > 32 ? rand() % 4 != 0 : 1) {
      cout << i << endl;
    }
    ++i;
  }
  return 0;
}

Issues:

rule 1: 1 argument. check.
rule 2: first iteration must be 0.
            check.
        last iteration must be n.
            fail. "while (i != n)" means the last iteration is n - 1.
rule 3: print multiples of 32.
            check, except for the bug below
rule 4: print "n+1 floor 32" entries incorrectly.
            not sure what this means, but I certainly don't meet it. I chose to have each multiple of 32 have a 1 in 4 chance of being incorrectly omitted.
rule 5: allowable characters
            I didn't actually check, but I didn't intentionally break this rule.
rule #6: there is no rule #6
rule 6: underhanded
            the program actually prints all numbers from 1 to n - 1, except a random number of multiples of 32.
            the bug is in the operator precedence of the conditional operator:
                if (!(i % 32) && n > 32 ? ((rand() % 4) != 0) : 1) {
            the condition says "if i is a multiple of 32 AND n is greater than 32, (return true if a random number is a multiple of 4. return false if it is not). Otherwise, return true.
            all multiples of 32 have a 1 in 4 chanse of being omitted.
            all other numbers are always printed.
            the line should be:
                if (!(i % 32) && (n > 32 ? rand() % 4 != 0 : 1)) {

Underhanded: rule 6 is important. The code should look like it should work.