text:
Create a Roman Numeral calculator
Create a basic calculator for Roman numerals.
Requirements

Supports +,-,*,/
Input and output should expect only one subtractor prefix per symbol (i.e. 3 can't be IIV because there are two I's before V)
Handling of the subtraction principle in input and output must at minimum support modern standard conventions, in which only powers of ten are subtracted from larger numbers (e.g. I,X,C are required subtractors but not V,L,D) and subtraction is never done from a number more than 10x the subtractor (e.g. IX must be supported but IC is not required).
Input and output should be left to right in order of value, starting with the largest (i.e. 19 = XIX not IXX, 10 is larger than 9)
Left to right, no operator precedence, as if you were using a hand calculator.
Supports whole positive numbers input/output between 1-4999 (no need for V̅)
No libraries that do roman numeral conversion for you

For you to decide

Case sensitivity
Spaces or no spaces on input
What happens if you get a decimal output. Truncate, no answer, error, etc..
What to do for output that you can't handle. Negatives or numbers to large to be printed.
Whether to support a more liberal use of the subtraction principle than the minimum requirement.

Extra Credit

-50 - Handle up to 99999 or larger. Symbols must include a vinculum

Sample input/output
XIX + LXXX                 (19+80)
XCIX

XCIX + I / L * D + IV      (99+1/50*500+4)
MIV

The shortest code wins.

(99+1/50*500+4) = (99+10+4) = 113, but your sample input/output says it is MIV (1004).

@Victor - strict left to right operation - no precedence rules - so 99 + 1 / 50 * 500 + 4 should be calculated as ((((99 + 1) / 50) * 500) + 4)

Is handling numbers like IM = 999 required?

@KendallFrey I would expect you could input IM. Whether the output is IM or CMXCIX for 999 is up to you. Both fit the requirements.

IM is non-standard for modern Roman numeral usage. Typically it's only the 4s and 9s of each order of magnitude (4, 9, 40, 90, 400, 900, etc.) that are done by subtraction. For 1999, MCMXCIX would be canonical, not MIM...watch the credits of any film from that year. Otherwise, where does it end? Are we also expected to support other non-standard subtractions like VL for 45? Would IC with a vinculum over the C have to be supported as 99999 for the bonus?

@JonathanVanMatre Can you think of a way to edit the question such to define the standard way of writing Roman numerals? I am not sure I understand the standard way enough to define it in the requirements (but it looks like most if not all of the answers follow it)

I've proposed an edit accordingly.

(99+1/50*500+4)=113 with my calculator (and to formula precedence)... If you want something else have to add parenthesis...

Seven years later: Time to update the accepted answer to this?

APL (Dyalog Unicode 18.0), 187 − 50 = 137 bytes (SBCS)
Full program using stdin/stdout. Requires 0-based indexing and space(s) between symbols and numbers.
d←,∘⌊⍨'IVXLCD'
'[a-z]'⎕R('\u&',⎕UCS 773)⊢d[∊(2×⌽⍳≢r)+{⍵=⍛⌽⍺0/⍨⍺×⍛⍮⍵-1}⌿0 5⊤1+⍎¨r←⍕⍎∊'\w+'⎕R{⍕(×\1,11⍴5 2)[d⍳⍵.Match](⊣+.×¯1*2</,)0}'(.)\pM'⎕R'\l1'⌽'-' '\*' '/' '\S+'⎕S'-⍨' '×' '÷⍨' '&'⊢⍞]

Try it online!

Full support for vinculum, so 1000 is written as I̅ (M is a modern addition)
Handles all positive results until 899999
Allows non-standard input, including, e.g. purely additive notation and too large/small subtractors
Includes support for factorial ! (and actually a bunch of other operations)

JavaScript (ES6), 238
c=s=>{X={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1}
n=eval('W='+s.replace(/[\w]+/g,n=>(o=0,n.replace(/[MDLV]|C[MD]?|X[CL]?|I[XV]?/g,d=>o+=X[d]),
o+';W=W')));o='';for(i in X)while(n>=X[i])o+=i,n-=X[i];return o}

Usage:
c("XIX + LXXX")
> "XCIX"
c('XCIX + I / L * D + IV')
> "MIV"

Annotated version:
/**
 * Process basic calculation for roman numerals.
 *
 * @param {String} s The calculation to perform
 * @return {String} The result in roman numerals
 */
c = s => {
  // Create a lookup table.
  X = {
    M: 1e3, CM: 900, D: 500, CD: 400, C: 100, XC: 90,
    L: 50,  XL: 40,  X: 10,  IX: 9,   V: 5,   IV: 4, I: 1
  };
  // Do the calculation.
  //
  // The evaluated string is instrumented to as below:
  //   99+1/50*500+4 -> W=99;W=W+1;W=W/50;W=W*500;W=W+4;W=W
  //                 -> 1004
  n = eval('W=' + s.replace(
    // Match all roman numerals.
    /[\w]+/g,
    // Convert the roman number into an integer.
    n => (
      o = 0,
      n.replace(
        /[MDLV]|C[MD]?|X[CL]?|I[XV]?/g,
        d => o += X[d]
      ),
      // Instrument number to operate left-side operations.
      o + ';W=W'
    )
  ));

  // Convert the result into roman numerals.
  o = '';
  for (i in X)
    while (n >= X[i])
      o += i,
      n -= X[i];

  // Return calculation result.
  return o
}

while(n>=X[i])o+=i,n-=X[i]; => for(;n>=X[i];n-=X[i])o+=i;

T-SQL, 1974 - 50 = 1924 bytes
I know that golfing in SQL is equivalent to playing 18 holes with nothing but a sand wedge, but I relished the challenge of this one, and I think I managed to do a few interesting things methodologically.
This does support the vinculum for both input and output. I adopted the convention of using a trailing tilde to represent it , so V~ is 5000, X~ is 10000, etc. It should also handle outputs up to 399,999 according to standard modern Roman numeral usage. After that, it will do partially non-standard Roman encoding of anything in INT's supported range.
Because it's all integer math, any non-integer results are implicitly rounded.
DECLARE @i VARCHAR(MAX)
SET @i='I+V*IV+IX*MXLVII+X~C~DCCVI'
SELECT @i

DECLARE @t TABLE(i INT IDENTITY,n VARCHAR(4),v INT)
DECLARE @u TABLE(n VARCHAR(50),v INT)
DECLARE @o TABLE(n INT IDENTITY,v CHAR(1))
DECLARE @r TABLE(n INT IDENTITY,v INT,r VARCHAR(MAX))
DECLARE @s TABLE(v INT,s VARCHAR(MAX))
DECLARE @p INT,@x VARCHAR(4000)='SELECT ',@j INT=1,@m INT,@y INT,@z VARCHAR(2),@q VARCHAR(50)='+-/*~]%'
INSERT @t(n,v) VALUES('i',1),('iv',4),('v',5),('ix',9),('x',10),('xl',50),('l',50),('xc',90),('c',100),('cd',400),('d',500),('cm',900),('m',1000),('mv~',4000),('v~',5000),('mx~',9000),('x~',10000),('x~l~',40000),('l~',50000),('x~c~',90000),('c~',100000)
INSERT @u VALUES('%i[^i'+@q,-2),('%v[^vi'+@q,-10),('%x[^xvi'+@q,-20),('%l[^lxvi'+@q,-100),('%c[^clxvi'+@q,-200),('%d[^dclxvi'+@q,-1000),('%mx~%',-2010),('%x~l~%',-20060),('%x~c~%',-20110)
WHILE PATINDEX('%[+-/*]%', @i)!=0
BEGIN
    SET @p=PATINDEX('%[+-/*]%', @i)
    INSERT @o(v) SELECT SUBSTRING(@i,@p,1)
    INSERT @r(r) SELECT SUBSTRING(@i,1,@p-1)
    SET @i=STUFF(@i,1,@p,'')
END
INSERT @r(r) SELECT @i
UPDATE r SET v=COALESCE(q.v,0) FROM @r r LEFT JOIN (SELECT r.r,SUM(u.v)v FROM @u u JOIN @r r ON r.r LIKE u.n GROUP BY r.r)q ON q.r=r.r
UPDATE r SET v=r.v+q.v FROM @r r JOIN (SELECT r.n,r.r,SUM((LEN(r.r)-LEN(REPLACE(r.r,t.n,REPLICATE(' ',LEN(t.n)-1))))*t.v) v FROM @r r JOIN @t t ON CHARINDEX(t.n,r.r) != 0 AND (LEN(t.n)=1 OR (LEN(t.n)=2 AND RIGHT(t.n,1)='~')) GROUP BY r.n,r.r) q ON q.r=r.r AND q.n = r.n
SELECT @m=MAX(n) FROM @o
SELECT @x=@x+REPLICATE('(',@m)+CAST(v AS VARCHAR) FROM @r WHERE n=1
WHILE @j<=@m
BEGIN
    SELECT @x=@x+o.v+CAST(r.v AS VARCHAR)+')'
    FROM @o o JOIN @r r ON r.n=o.n+1 WHERE o.n=@j
    SET @j=@j+1
END
INSERT @s(v,s) EXEC(@x+',''''')
UPDATE @s SET s=s+CAST(v AS VARCHAR(MAX))+' = '
SET @j=21
WHILE @j>0
BEGIN
    SELECT @y=v,@z=n FROM @t WHERE i = @j
    WHILE @y<=(SELECT v FROM @s)
    BEGIN
        UPDATE @s SET v=v-@y,s=s+@z
    END
    SET @j=@j-1
END
SELECT @x+' = '+UPPER(s) FROM @s

I'm still tinkering with a set-based solution to replace some of the WHILE looping that might whittle down the byte count and be a more elegant example of idiomatic SQL. There are also some bytes to be gained by reducing use of table aliases to a bare minimum. But as it's essentially un-winnable in this language, I'm mostly just here to show off my Don Quixote outfit. :)
SELECT @i at the top repeats the input:
I+V*IV+IX*MXLVII+X~C~DCCVI

And the SELECT at the end returns:
SELECT (((((1+5)*4)+9)*1047)+90706) = 125257 = C~X~X~V~CCLVII

And you can test it yourself at this SQLFiddle
And I will be returning to add some commentary on how it works, because why post an obviously losing answer if you're not going to exploit it for educational value?

Javascript - 482 476 characters
String.prototype.m=String.prototype.replace;eval("function r(a){return a>999?'Mk1e3j899?'CMk900j499?'Dk500j399?'CDk400j99?'Ck100j89?'XCk90j49?'Lk50j39?'XLk40j9?'Xk10j8?'IX':a>4?'Vk5j3?'IV':a>0?'Ik1):''}".m(/k/g,"'+r(a-").m(/j/g,"):a>"));s=prompt();h=s.match(/\w+/gi);for(k in h)s=s.m(h[k],eval(eval("'0'+h[k].m(/IVu4pIXu9pXLu40pXCu90pCDu400pCMu900pMu1000pDu500pCu100pLu50pXu10pVu5pIu1')".m(/u/g,"/g,'+").m(/p/g,"').m(/")))+")");for(k in h)s="("+s;alert(r(Math.floor(eval(s))))

The sample input/output works:
XIX + LXXX -> XCIX
XCIX + I / L * D + IV -> MIV

It badly handles large numbers too:
MMM+MMM -> MMMMMM
M*C -> MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM

And it accepts, but does not requires, spaces too.
But, since I was golfing it has some problems:

It does not validates if the input is well-formed. If the input is not well-formed, the behaviour is undefined (and in practice it is very bizarre and strange).
It truncates fraction numbers on output (but it is able to do intermediate calculations with them).
It really abuses the eval function.
It does not attempt to handle negative numbers.
It is case-sensitive.

This alternative version handles numbers over 5000 upto 99999, but it has 600 598 584 characters:
String.prototype.m=String.prototype.replace;eval("function r(a){return a>8zz?'XqCqk9e4j4zz?'Lqk5e4j3zz?'XqLqk4e4jzz?'Xqk1e4j89z?'IqXqk9e3j49z?'Vqk5e3j9z?'Mk1e3j8z?'CMk900j4z?'Dk500j3z?'CDk400jz?'Ck100j89?'XCk90j49?'Lk50j39?'XLk40j9?'Xk10j8?'IX':a>4?'Vk5j3?'IV':a>0?'Ik1):''}".m(/k/g,"'+r(a-").m(/j/g,"):a>").m(/q/g,"\u0305").m(/z/g,"99"));s=prompt();h=s.match(/\w+/gi);for(k in h)s=s.m(h[k],eval(eval("'0'+h[k].m(/IVu4pIXu9pXLu40pXCu90pCDu400pCMu900pMu1000pDu500pCu100pLu50pXu10pVu5pIu1')".m(/u/g,"/g,'+").m(/p/g,"').m(/")))+")");for(k in h)s="("+s;console.log(r(Math.floor(eval(s))))

I don't think the -20 applies: see vinculum

Agree with @SeanCheshire here. For the larger number handling the intention is to add a vinculum over the numeral to be 1000 times the value of what it normally is. Maybe it should be larger than a -20 so it make it worth trying for people.

@Danny I added a version which handles the vinculus, but it increases the code in 116 characters.

Javascript  479 361 348 278 253
303 characters - 50 for supporting numbers up to 1 million, complete with vinculum support:
function p(s){s=s[r](/(^|[*\/+-])/g,"0;s$1=");for(i in v){f=R("\\b"+i);while(f.test(s))s=s[r](f,v[i]+"+")}eval(s+"0");h="";for(i in v)while(s>=v[i]){h+=i;s-=v[i]}return h}v={M̅:1e6,D̅:5e5,C̅:1e5,L̅:5e4,X̅:1e4,V̅:5e3,M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1};r="replace";R=RegExp

Usage: p(text), e.g., p('XIX + LXXX') returns XCIX.
Code with explanatory comments:
// Array mapping characters to values
v={M¯:1e6,D¯:5e5,C¯:1e5,L¯:5e4,X¯:1e4,V¯:5e3,M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1};
// Shortcut for String.replace
r='replace';
R=RegExp;

// The heart of the program
function p(s) {
    // Replace operators with ";s+=", ";s-=", and so on
    s=s[r](/(^|[*\/+-])/g,'0;s$1=');
    // Loop over the character map and replace all letters with numbers
    for(i in v){
        f=R('\\b'+i);
        while(f.test(s))
            s=s[r](f, v[i]+'+')
    }
    eval(s+'0');
    // Set up our return string
    h='';
    // Replace digits with characters
    for(i in v)
        while(s>=v[i]) {
            h+=i;
            s-=v[i];
        }
    return h;
}

This works for the given samples and for all others I have tried. Examples:
XIX + LXXX = XCIX
XCIX + I / L * D + IV = MIV
XL + IX/VII + II * XIX = CLXXI
CD + C + XL + X + I = DLI
M̅ + I = M̅I
MMMM + M = V̅

Ruby 2.1, 353 (and many other iterations), 295 - 50 = 245
The vinculum handling adds ~23 characters.
This handles "IL" or "VM" in the input, and fails without error on negatives (goes to high ints) or decimals (truncates), or any spaces.  Now also handles a negative first number (though if the total is negative, it still fails poorly).  Also fails poorly if you start with * or / or if the result is 4 million or larger.
Uses Object#send for "hand-calculator" functionality.
m=%w{I V X L C D M V̅ X̅ L̅ C̅ D̅ M̅};n=m.zip((0..12).map{|v|(v%2*4+1)*10**(v/2)}).to_h
d=0
gets.scan(/([-+*\/])?([A-Z̅]+)/){|o,l|f=t=0
l.scan(/.̅?/){t-=2*f if f<v=n[$&]
t+=f=v}
d=d.send o||:+,t}
7.downto(1){|v|z=10**v
y=(d%z)*10/z
q,w,e=m[v*2-2,3]
$><<(y>8?q+e : y<4?q*y : y<5?q+w : w+q*(y-5))}

Ungolfed:
m=%w{I V X L C D M V̅ X̅ L̅ C̅ D̅ M̅} # roman numerals
n=m.zip((0..12).map{|v|(v%2*4+1)*10**(v/2)}).to_h # map symbols to values
d=0
gets. # get input and...
  scan(/([-+*\/])?([A-Z̅]+)/) { |l,o|  # for each optional operator plus number
    f=t=0
    l.scan(/.̅?/){                           # read the number in one letter at a time
      t -= 2 * f if f < (v=n[$&])           # if the number's greater than the prev, subtract the prev twice since you already added it
      t += (f = v)                          # add this, and set prev to this number
    }
    d = d.send((o || :+), t)                # now that we've built our number, "o" it to the running total (default to +)
}
7.upto(1) { |v|                        # We now print the output string from left to right
  z = 10**v                            # z = [10, 100, 1000, etc.]
  y = (d%z)*10/z                       # if d is 167 and z is 100, y = 67/10 = 6
  q,w,e = m[v*2-2,3]                   # q,w,e = X, L, C
  $><< (                               # print:
    y>8 ? q+e :                        # if y==9,    XC
      y<4 ? q*y :                      # if y<4,     X*y
        y>3 ? q+w :                    # if y==4,    XL
          q*(y-5)                      # else,       L + X*(y-5)
  )
}

Python 2 - 427 418 404 401 396 395 392 characters
Reads from standard input.  It only handles uppercase (could make it case-insensitive at the cost of 8 extra characters) and requires spaces.  Does no validation--I haven't tested to see how it breaks in various cases.  It does, however, handle numbers like VC = 95.
N=['?M','DC','LX','VI'];t=0;o='+'
for q in raw_input().split():
 if q in"+-*/":o=q;continue
 n=s=0;X=1
 for l in q:
  x=''.join(N).find(l);v=(5-x%2*4)*10**(3-x/2)
  if X<x:n+=s;s=v;X=x
  elif X>x:n+=v-s;s=0
  else:n+=v+s;s=0
 exec"t"+o+"=n+s"
r=t/1000*'M'
for p,d in enumerate("%04d"%(t%1e3)):
 i="49".find(d);g=N[p]
 if i<0:
  if'4'<d:r+=g[0]
  r+=int(d)%5*g[1]
 else:r+=g[1]+N[p-i][i]
print r

And the ungolfed version:
# Numerals grouped by powers of 10
N = ['?M','DC','LX','VI']
# Start with zero plus whatever the first number is
t = 0
o = '+'
for q in raw_input().split():
    if q in "+-*/":
        # An operator; store it and skip to the next entry
        o = q
        continue
    # n holds the converted Roman numeral, s is a temp storage variable
    n = s = 0
    # X stores our current index moving left-to-right in the string '?MDCLXVI'
    X = 1
    for l in q:
        # x is the index of the current letter in '?MDCLXVI'
        x = ''.join(N).find(l)
        # Calculate the value of this letter based on x
        v = (5 - x%2 * 4) * 10 ** (3 - x/2)
        if X < x:
            # We're moving forward in the list, e.g. CX
            n += s      # Add in any previously-stored value
            s = v       # Store this value in case we have something like CXL
            X = x       # Advance the index
        elif X > x:
            # Moving backward, e.g. XC
            n += v - s  # Add the current value and subtract the stored one
            s=0
        else:
            # Same index as before, e.g. XX
            n += v + s  # Add the current value and any stored one
            s = 0
    # Update total using operator and value (including leftover stored value
    # if any)
    exec "t" + o + "=n+s"

# Now convert the answer back to Roman numerals
# Special-case the thousands digit
r = t / 1000 * 'M'
# Loop over the number mod 1000, padded with zeroes to four digits (to make
# the indices come out right)
for p, d in enumerate("%04d" % (t % 1e3)):
    i = "49".find(d)
    g = N[p]
    if i < 0:
        # i == -1, thus d isn't '4' or '9'
        if '4' < d:
            # >= 5, so add the 5's letter
            r += g[0]
        # ... plus (digit % 5) copies of the 1's letter
        r += int(d) % 5 * g[1]
    else:
        # If it's a 4 or 9, add the 1's letter plus the appropriate
        # larger-valued letter
        r += g[1] + N[p-i][i]
print r

I have a feeling Perl would have been better, but I don't know enough of it.  For a first stab at code golf, though, I feel pretty good about this.

PHP — 549 525 524 520 bytes
Nothing too innovative: normalizes the operators to ensure left to right precedence, converts Roman to decimal, runs eval on the statement, e.g. XCIX + I / L * D + IV is converted to something like return (((((+90 +9) + (+1)) / (+50)) * (+500)) + (+4));, then converts decimal back to Roman.

final results are truncated
answers less than 1 come back blank
results are undefined if given incorrect input

$f='str_replace';$g='str_split';$c=array('M'=>1e3,'CM'=>900,'D'=>500,'CD'=>400,'C'=>100,'XC'=>90,'L'=>50,'XL'=>40,'X'=>10,'IX'=>9,'V'=>5,'IV'=>4,'I'=>1);$j='['.$f(array('+','-','*','/'),array('])+[','])-[','])*[','])/['), $argv[1]).'])';$j=str_repeat('(',substr_count($j,')')).$j;$j=$f('[','(',$j);$j=$f(']',')',$j);foreach($g('IVIXXLXCCDCM',2)as$w)$j=$f($w,'+'.$c[$w],$j);foreach($g('IVXLCDM')as$w)$j=$f($w,'+'.$c[$w],$j);$k=eval('return '.$j.';');$l='';foreach($c as$a=>$b){while($k>=$b){$l.=$a;$k-=$b;}}print$l."\n";
e.g.
$ php roman.php 'XCIX + I / L * D + IV' — test case
MIV                                     — 1004

$ php roman.php 'XXXII * LIX'           — 32 × 59
MDCCCLXXXVIII                           — 1888

Python - 446 bytes
This could be improved considerably. I felt I had to take the first swing using Python. It does 3 things on the first pass

tokenizes the numbers and operators
evaluates the numbers, and enlarges the symbol table x to include all possible combinations encountered (even if they are not used). For example, while XIX is being lexed, the partial values of "X":10, "XI":11 and "XIX":19 are added to the symbol table
inserts nested parens to enforce left-to-right evaluation

At the end, it calls eval on the original string (except with added parens) and gives it the symbol table.
Then I just pasted in a known solution to convert integer to Roman, since I had worked on this long enough... please feel free to improve so that I learn something new :)

m=zip((1000,900,500,400,100,90,50,40,10,9,5,4,1),
('M','CM','D','CD','C','XC','L','XL','X','IX','V','IV','I'))
def doit(s):
 x={'M':1e3,'D':500,'C':100,'L':50,'X':10,'V':5,'I':1};y=[];z='';a='0';s='+'+s
 for c in s.upper():
  if c in x:
   z+=c;y.append(x[c])
   if len(y)>1and y[-1]>y[-2]:y[-2]*=-1
   x[z]=sum(y)
  elif c in"+/*-":a='('+a+z+')'+c;y=[];z=''
 a+=z;i=eval(a,x);r = ''
 for n,c in m:d=int(i/n);r+=c*d;i-=n*d
 return r

print doit("XIX + LXXX")
print doit("XCIX + I / L * D + IV")

MATLAB - 543 bytes
I tried not to look at others' answers before working on my own, although my approach ended up similar regardless. I use a regular expression to match word characters (the numbers) or operators, which splits up the input into a cell array alternating between numbers and operators. I then replace the roman numerals in every other cell with itself and a plus sign, using order of precedence on the groups to ensure proper grouping. I define variables with the same name as each split group and use an eval statement on the split roman numeral to convert it to a value with a closing parenthese. I then concatenate the whole list of values and operators with proper opening parentheses to ensure strict left-to-right order of operations. I then deconstruct the resulting number digit-by-digit and convert it to the proper roman numeral based on its "power".
function n=m(I)
e=regexp(I,'\w+|[\+\-\*\/]','match');CM=900;XC=90;IX=9;CD=400;XL=40;IV=4;M=1e3;D=500;C=100;L=50;X=10;V=5;I=1;e(1:2:end)=cellfun(@(x) [num2str(evalin('caller',[x '0'])) ')'],regexprep(e(1:2:end),'CM|XC|IX|CD|XL|IV|.?','$0+'),'un',0);S=num2str(eval(strcat(repmat('(',1,(length(e)+1)/2),e{:})));n='';I='IXCM';V='VLD ';l=length(S);for i=1:l
p=l-i+1;a=eval(S(i));if p>3
n=repmat('M',1,a);continue
end
b=a>4;switch a
case 4
n=[n I(p) V(p)];case 9
n=[n I(p:p+1)];otherwise
n=[n repmat(V(p),1,b) repmat(I(p),1,a-5*b)];end
end

ungolfed:
function n=m(I)
e=regexp(I,'\w+|[\+\-\*\/]','match'); % match roman numerals or operators
CM=900;XC=90;IX=9; % nines
CD=400;XL=40;IV=4; % fours
M=1e3;D=500;C=100; % single character numbers (ones and fives)
L=50;X=10;V=5;I=1;
e(1:2:end)=cellfun(@(x) [num2str(evalin('caller',[x '0'])) ')'],... % Evaluate each group and add a parenthesis
                   regexprep(e(1:2:end),'CM|XC|IX|CD|XL|IV|.?','$0+'),'un',0); % replace each group or single digit with itself and a +
S=num2str(eval(strcat(repmat('(',1,(length(e)+1)/2),e{:}))); % concatenate the split string and evaluate with proper parentheses for left-to-right Order of Operations
n='';         % initialize output
I='IXCM';     % Define ones and fives
V='VLD ';
l=length(S);
for i=1:l
p=l-i+1;
a=eval(S(i));
if p>3              % if the number has 4 or more digits, just add a bunch of Ms
n=repmat('M',1,a);
continue
end
b=a>4;
switch a
case 4
n=[n I(p) V(p)]; % If the digit is 4, add the proper 1 and 5
case 9
n=[n I(p:p+1)]; % If the digit is 9, add the correct 9 group
otherwise
n=[n repmat(V(p),1,b) repmat(I(p),1,a-5*b)]; % Add a 5 if the digit is greater than 4. add 1s for either the digit value (1,2,3) or the value - 5 (6,7,8)
end
end

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


text:
Flappy Bird Clones :)
Everyone's been freaking out about that stupid "Flappy Bird" game being removed. So, your task is to crate a Flappy Bird Clone game. Its really simple. Here are the guide lines:

It can use either ascii art or real images
You can make your "bird" flap with either a click or a key press
It should try to be as short as possible, hence the code-golf tag.

Here's an example: http://www.reddit.com/r/learnprogramming/comments/1xiimx/i_couldnt_sleep_so_i_cloned_your_flappy_bird/
In order to be a "Flappy Bird Clone," your game needs to have the following:

A bird, or other character
The "bird" should move slightly up when a key is pressed or you click/tap
If there is no clicking/tapping/etc, the "bird" should rapidly move downwards
Pipes or other obstacles should move leftwards on the screen, creating the illusion that the bird is moving
The pipes should have a small gap for the bird to fly through.
Every time you pass through a gap between pipes, your score increases by 1.
If you hit a pipe or the ground, the game ends and your score is displayed.

It doesn't really need to be a "bird" or a "pipe," it can all be ascii. Here's a very minimal example of a flappy bird screen:

/-----[4]-----\
| ||      ||  |
| ||      ¯¯  |
| ||  O>      |
| ¯¯      __  |
| __      ||  |
| ||      ||  |
\-------------/

A question should ideally be self-contained, and should certainly contain at least a broad-brush spec.

As it stands, there appears to be a little too much subjectivity in what's considered a valid submission

There. I put some guidelines as to makes up a "flappy bird clone"

I did this a couple weeks ago. Maybe I'll golf it when I get some time: http://cwhart.co/nyanpybird/

I really really want to see an ASCII art version!

@SuperScript Checkout my answer... http://codegolf.stackexchange.com/a/23556/4178

Wait, really? Flappy bird got removed?

Javascript+jQuery (ASCII Art) - 571 524 491 464
l=$('[id$=52] h4~pre').click(()=>{m=1}),o=[],d=0,e=4,m=1;setInterval(()=>{t=Array(153);s=~~(d/10-0.99);d++;d%10?0:o[d+20]=~~(Math.random()*5)+1;for(i=-1;k=o[i+d],i<17;i++)if(k--)for(j=-1;c=j==k||j-k==4?'-':j-k>0&&j-k<4?0:'|',j<9;j++)i>-1?t[j*17+i]=c:0,i<16?t[j*17+i+1]=c:0;m-=.2;e-=m;if(e<0||e>10||t[~~e*17+8])e=4,m=1,d=0,o=[];t[~~e*17+8]='>';r='|-------['+s+']-------';for(i=0;z=t[i]||' ',i<153;i++)i%17?r+=z:r+='|\n|'+z;r+='|\n|-----------------|';l.html(r);},150)

Demo
Open the dev tools console (F12) and run the above code in this page to use the below demo (right now, go ahead!):
|-------[5]-------|
|    ||        -- |
|    ||           |
|    ||           |
|    --           |
|              -- |
|              || |
|              || |
|    --  >     || |
|    ||        || |
|-----------------|

Known minor bugs:

If you get a double-digit score, it messes up the layout

It is NOT easy!!! (but the original wasn't either)

There's a tradeoff between efficiency and golfedness

Feel free to comment with your highscore.
Also, this is my first Code Golf post, so suggestions on compression, etc. will be welcomed

You can remove var keyword and variable declaration. You can also replace Array(153) by [] and probably can replace ~~(Math.random()*5)+1 by 1+new Date%5

If you ignore the layout, skip jQuery and add the HTML it is 416 bytes: http://jsbin.com/flap/1/edit?html,output

Scored 17. I have no life, I know.

Known_minor_bugs += "irritating, unwanted and distracting text selections when double clicking";

This is apparently really addicting for some reason. I got a 19

Javascript + jQuery (997)
Tested on Chrome 32, Firefox 27, IE9
Open Console (F12) from this page and copy/paste the following code.
scroll(0,0);h=1/30;p=[];r=320;n=0;w=80;f=2.5;o=80;t=setInterval;$('#question').children().hide().end().append('

').append('

').click(function(){v=100});$('#s').css({position:'relative',margin:'auto',border:'2px solid',width:200,height:r}).append('');$('').appendTo('head');function u(){$('#m').text('score '+m+' (max '+n+')')}function i(){x=r/2;v=0;m=0;p.length=0;u()}i();t("v-=h*100;x+=h*v;if(x<0||x>r)i();$('.p').remove();for(j=0;j
200){p.shift();j--;m++;if(m>n)n=m;u();}else if((p[j].r>165&&p[j].r<185)&&(x
p[j].h+o))i();else{$('

').appendTo('#s').css({bottom:0,right:p[j].r,height:p[j].h});$('

').appendTo('#s').css({bottom:p[j].h+o,right:p[j].r,height:320-p[j].h-o})}}$('#b').css({position:'absolute',left:0,bottom:x-25})",h*1e3);t("p.push({h:Math.random()*(r-o),r:0})",f*1e3)

The game replace the question block of this page.
You have to click on the game frame to make the bird fly.

Ungolfed and commented version :
$('#question').children().hide();
$('#question').append('

');
$('#question').append('

');
$('#scene').css({position:'relative',margin:'auto',border:'2px solid black',width:'200',height:'320'});
$('#scene').append('');
$('#bird').css({display:'block',position:'absolute',left:0,'pointer-events':'none',margin:'0 auto'});
$(window).scrollTop(0);

//CONFIGURATION
var dt=1/30,      //delta timestep (typically 30Hz)
    pipevel=80,   //pipe velocity (in pixels per second)
    pipefreq=2.5, //pipe spawn frequency (in second)
    holesize=80,  //hole size (in pixels)
    gravity=-100, //gravity (in pixels per square second)
    punchvel=100; //velocity punch when clicked (in pixels per second)

var x, y, pipes=[], roof=$('#scene').height(), score, maxscore=0;

function updateScore() {
  $('#score').text('Score : '+score+' (max : '+maxscore+')');
}

function init() {
  x=roof/2; //position
  v=0; //velocity
  score=0;
  pipes.length=0;

  updateScore();
}

function step() {
  //euler integration
  v+=dt*gravity;
  x+=dt*v;

  if (x<0 || x>roof)  init();

  //pipes
  $('.pipe').remove();
  for (i=0; i<pipes.length; i++) {
    pipes[i].rightpos += dt*pipevel;
    if (pipes[i].rightpos > 200) {
      pipes.shift();
      i--;
      score++;
      if (score>maxscore) maxscore=score;
      updateScore();
    } else if ((pipes[i].rightpos > 165 && pipes[i].rightpos < 185) && (x < pipes[i].holepos || x > pipes[i].holepos+holesize)) {
      //collision
      init();
    } else {
      $('#scene').append('

');
      $('#scene').append('

');
    }
  }

  $('#bird').css({bottom:Math.floor(x)-25});

  setTimeout(step, dt*1000);
}

$('#question').click(function() {
  v=punchvel;
});

function addPipe() {
  pipes.push({holepos:Math.random()*(roof-holesize),rightpos:0});
  setTimeout(addPipe, pipefreq*1000);
}

init();
setTimeout(step, dt*1000);
setTimeout(addPipe, pipefreq*1000);

You can easily modify the configuration (gravity, pipe velocity...), have a look at commented version.

Works fine in Firefox 27 as well. Nicely done +1

Thanks, works on IE9 too, so I guess it works on any decent browser :)

nice work :) and like usual on javascript here abusing the question as target :P

I'm curious: what did you use to develop the script? surely not Console F12 ?!

@MarkLakata Why not? Chrome devtools is more than capable.

High score of 14. This game is too hard :(

Also, change v=100 to v+=50 for a more stable control scheme (no character savings, though).

@MarkLakata, I used the Chrome Console.

@JoeZ., I have never played to the original flappy bird, I thought there was a velocity limit. But I think my game is too easy compared to the original, the gravity is low and the pipes move slowly.

With the current control scheme, it's too easy to accidentally misclick and then not be able to fall far enough to get to the next hole (and then being unable to do anything about it).

@JoeZ. isn't it the goal of the game ? To not misclick ? :)

What I'm saying is that it's too easy to misclick somewhere in the middle, and it's also too hard to click properly because your punch always sets you to the same initial velocity regardless of how fast you've already gone down.

@JoeZ. ok go it !

BTW, I found a bug - when you minimize the window for a few seconds and reopen it, you get about 5 walls at once.

Floppy Dragon, JavaScript, 1024b
I'm making this game for the current js1k compo ( http://js1k.com )
Play: http://js1k.com/2014-dragons/demo/1704
_='c.scale(,    ;ontouchH=onmousedown=onkeydowif(e){    }else h=45,d=1};(Eq";Rect(0,0,^,^9Q"-k,0Q+N),0()-k,2E3980-(+3)N(+3)),Y(p="fEFf&{{~_=,;=vviJ.jfVi/.OoyizyhkhEwf74)\\n$fwwuvtU`"+(10<h?"iZ[*)yj:*im**y|Ktdww54#5Dy\\iz[Kzi[Jiijk[e@1!":"zl]LfU{\\lKtBUh{zzU66iigig5\\n&iiyz{vfwwiyDfwiiE"0"v=i-e,w=(j-=h)-eG in p)y=8>>4),z=16&15),Iv+=e?y:z,w+=e?-z:y(dW(h-=6dW!eW(k+=Q,^<kW(k-=^)!dXeX(k+280)%8X(f++,Q<lWl--if(q>jX9q<jX!((k+3)%8)W(j<qXj>2q))e=40;fff";c.font="6em Arial";dWf1,5dX"#FloppyDragon"11,5eW"score"4,4e?"reH":d?"":"H"5,6setTimeout(n,l)})()I40*o-k,a.width/()/2-30*    d=e=f=h=0;g=[];G=0;Y>o;o++)=g[o+Y]=8*Math.random()|0;i=j=3;k=Q;l=qc.fill;c.beginPath(c.moveTo(Style="#G=2E3;o--;)o%Q?,a.height/Y1*g[Q*~~(k/8)+Q]+);g[o]-2*(p.charCodeAt(o)Text(00n=function(){4*):(,1*Gfor(oHstartIc.lineTo(N),-4,1*Q20W&&X||Y1E3^4E4q50';for(Y in $='q^YXWQNIHG    ')with(_.split($[Y]))_=join(pop());eval(_)

All feedbacks and new ideas are welcome!

This is even harder than Flappy Bird. It would be easier to play if you made a keypress trigger the flap action, but I realize this is code golf and more features means more code.

no it's okay, I can try to add keypress support if you think it's useful...

@crazedgremlin keypress control was added in the latest version ;)

Cool! I can't get past 10, but it's still cool.

Color Animation and Physics; Pure JavaScript, 457 (335) bytes
This is my first post in this forum; I made this code and retrospectively found this thread to post it in.
Here's the code encapsulated in HTML, ready to be copy/pasted in to an html file:

Made by Thomas Kaldahl

It has pixel perfect collisions, accurate quadratic physics, and smooth color animations, all in 457 bytes worth of purely independent offline Javascript code, shown ungolfed here in greater detail and explanation:

    Made by Thomas Kaldahl

For fun, here's a 1066 byte version with fancier graphics:

Made by Thomas Kaldahl

Also, is it cheating to use a compression system like DEFLATE?
Below is the ASCII85 code for a DEFLATEd version of the code:
By the way, compressed it is 335 bytes total.

Gapon95_Wi'Kf'c(i##6'h,+cM\JZeFO<h;$W'#A1',RqNigBH02C'#R$m]<i<X#6GR`2pE<Ri5mu-n%cVPrsJe:*R^pnr9bI@[DAZnPP02A^!.$MN/@`U7l5gm!!Vr4>A;P?u[Pk8]jCnOP%dIu?`fWql>"tuO4/KbIWgK;7/iJN'f2,hnFg8e.^SO*t\*`,3JBn6j(f`O#],M0;5Sa35Zc@*XaBs@N%]k\M76qa[.ie7n(^*Z5G-lfhUZ3F#'%,X17Pj1u]L)LjpO6XbIl%N3tJhTsab8oV1T(?MC$9mT;90VMmnfBNKEY(^'UV4c?SW':X(!4,*WCY+f;19eQ?`FK0I"(uDe:f&XV&^Rc+'SWRIbd8Lj9bG.l(MRUc1G8HoUsn#H\V(8"Y$/TT(^kATb(OreGfWH7uIf

This looks great, but unfortunately for [tag:codr-golf] questions we require golfed code.

@NoOneIsHere please read the post and view the golfed code for yourself

I'm sorry, I see now. This is a great answer.

C, 386 351 347 341 bytes (Windows, MinGW), 332 with a terminal emulator

Certainly not the prettiest entry, but it captures the core mechanics of flappy bird: The bird accelerates downwards, pressing a key makes him jump up, touching the pipes or the edges of the screen ends the game, score is the number of cleared pipes.
#import<windows.h>
#define T(x)P[v*10+x]=
char P[71];X,Y,W,s;main(v){srand(time(0));for(float y=1,t=0;!(v<0|v>6|(v<Y|v>=Y+W)&X>0&X<3);Sleep(99)){y+=t=kbhit()?getch(),-.9:t+.3;--X<0?X=8,Y=rand()%3+1,W=rand()%2+2:X-1||++s;memset(P,32,70);for(v=0;v<7;T(9)10,T(X)v<Y|v++>=Y+W?35:32);v=y;T(1)79;T(2)62;system("cls");printf("%s\nSCORE: %d",P,s);}}

It can be shortened to 333 bytes, if a POSIX terminal emulator is used (like Cmder):
#import<windows.h>
#define T(x)P[v*10+x]=
char P[71];X,Y,W,s;main(v){srand(time(0));for(float y=1,t=0;!(v<0|v>6|(v<Y|v>=Y+W)&X>0&X<3);Sleep(99)){y+=t=kbhit()?getch(),-.9:t+.3;--X<0?X=8,Y=rand()%3+1,W=rand()%2+2:X-1||++s;memset(P,32,70);for(v=0;v<7;T(9)10,T(X)v<Y|v++>=Y+W?35:32);v=y;T(1)79;T(2)62;printf("\033c%s\nSCORE: %d",P,s);}}

Objective C - ungolfed
Possibly the worst code I have ever written.

You can download the binary here: AsciiBird Download Binary
Tap the control key frantically to keep the bird in the air!
This was compiled by Xcode and run in Terminal. It has colors!
Protip: Resize your terminal's window so you don't see a backlog of screen refreshes.
main.m:

#import <Foundation/Foundation.h>
#import "ABManager.h"

void drawScreen(int counter)
{
    __block struct ABPoint thisPoint;
    thisPoint.x = 0;
    thisPoint.y = 0;

    __block ABManager *man = [ABManager sharedManager];
    [man.screen enumerateObjectsUsingBlock:^(NSString *c, NSUInteger idx, BOOL *stop)
     {
         NSString *c2 = c;
         NSMutableArray *newObstacles = [[NSMutableArray alloc] init];
         for (NSValue *s in man.obstacles)
         {
             struct ABPoint o;
             [s getValue:&o];

             if (thisPoint.x == o.x)
             {
                 if (thisPoint.y != o.y && thisPoint.y != (o.y + 1) && thisPoint.y != (o.y - 1))
                 {
                     c2 = @"\033[1;33m|\033[0m";
                 }
                 else
                 {
                     if (counter == 0 && thisPoint.y < o.y)
                     {
                         o.x = o.x - 1;

                         if (o.x < 0)
                         {
                             o.x = 49;
                             o.y = (arc4random() % 11) + 1;
                         }

                         if (man.charPos.x == o.x)
                         {
                             man.score = man.score + 1;
                         }
                     }
                 }
             }
             [newObstacles addObject:[NSValue valueWithBytes:&o objCType:@encode(struct ABPoint)]];
         }

         man.obstacles = [[NSMutableArray alloc] initWithArray: newObstacles];

         if (thisPoint.x == man.charPos.x && thisPoint.y == man.charPos.y)
         {
             printf("\033[1;35m>\033[0m");

             if ([c2 isEqualToString:@"\033[1;33m|\033[0m"])
             {
                 man.shouldExit = TRUE;
             }
         }
         else
         {
             printf("%s", [c2 UTF8String]);
         }

         if (idx % 50 == 49)
         {
             printf("\n");
             thisPoint.y = thisPoint.y + 1;
             thisPoint.x = 0;
         }
         else
         {
             thisPoint.x = thisPoint.x + 1;
         }
     }];
}

int main(int argc, const char * argv[])
{

    @autoreleasepool {

        ABManager *man = [ABManager sharedManager];
        int count = 0;
        BOOL ignoreKeypress = FALSE;
        while (TRUE)
        {
            if (CGEventSourceKeyState(kCGEventSourceStateCombinedSessionState,59) && !ignoreKeypress)
            {
                ignoreKeypress = TRUE;
                struct ABPoint p = man.charPos;
                p.y = p.y - 2;
                man.charPos = p;
            }
            else
            {
                ignoreKeypress = CGEventSourceKeyState(kCGEventSourceStateCombinedSessionState,59);

                if (count > 3)
                {
                    count = 0;
                    struct ABPoint p = man.charPos;
                    p.y = p.y + 1;
                    man.charPos = p;
                }
                else
                {
                    count = count + 1;
                }
            }

            if (man.charPos.y < -1 || man.charPos.y > 11 || man.shouldExit)
            {
                exit(1);
            }

            printf("\n\n\n\n\n");
            printf("\033[1;36m[\033[0m\033[1;30mHacky Bird\033[0m\033[1;36m]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\033[0m\n");
            drawScreen(count);
            printf("\033[1;32m[\033[0m\033[1;31mScore: %li\033[0m\033[1;32m]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\033[0m\n", (long)man.score);

            [NSThread sleepForTimeInterval:0.0157];
        }

    }
}

ABManager.h

#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>

struct ABPoint {
    NSInteger x;
    NSInteger y;
};

@interface ABManager : NSObject
{

}

@property (nonatomic, readwrite) NSMutableArray *screen;
@property (nonatomic, readwrite) NSMutableArray *obstacles;
@property (nonatomic, readwrite) struct ABPoint charPos;
@property (nonatomic, readwrite) NSInteger score;
@property (nonatomic, readwrite) BOOL shouldExit;;

+ (id)sharedManager;

@end

ABManager.m

#import "ABManager.h"

@implementation ABManager
+ (id)sharedManager {
    static ABManager *sharedMyManager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedMyManager = [[self alloc] init];
    });
    return sharedMyManager;
}

- (id)init
{
    if (self = [super init]) {

        self.screen = [[NSMutableArray alloc] init];
        for (NSUInteger i=0; i < 600; i++)
        {
            [self.screen addObject:@" "];
        }

        self.score = 0;

        self.shouldExit = FALSE;

        struct ABPoint p;
        p.x = 5;
        p.y = 0;

        self.charPos = p;

        struct ABPoint o;
        o.x = 10;
        o.y = 5;

        struct ABPoint o2;
        o2.x = 30;
        o2.y = 5;

        self.obstacles = [[NSMutableArray alloc] initWithArray:@[[NSValue valueWithBytes:&o objCType:@encode(struct ABPoint)],[NSValue valueWithBytes:&o2 objCType:@encode(struct ABPoint)]]];
    }

    return self;
}

@end

source: Stack Exchange

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

sort: votes


text:
Compute the greater common divisor & the smallest common multiple of N numbers
Your mission is to write 2 functions that accept a list of N integers (positive or negative).
N can be higher than 2.
The first one returns the greater common divisor of the N numbers
Example: [10, 15, 20] -> 5
the second one returns the smallest common multiple of the N numbers
Example: [10, 15, 20] => 60
Smallest code (in number of characters) wins!

If you're going to require support for negative integers in the input, you need to make clear how you're defining LCM and give relevant test cases.

Ruby 38 characters
g=->a{a.inject:gcd}
l=->a{a.inject:lcm}

demo:
ar = [10,15,20]
p g[ar] #=> 5
p l[ar] #=> 60

J, 12 characters
g=.+./
l=.*./

A bit pointless giving them aliases like this really.

Smalltalk (Smalltalk/X) (73 chars)
a:=#(10 15 20).
g:=a fold:[:i :e|i gcd:e].
l:=a fold:[:i :e|i lcm:e].

without fold: (Ansi Smalltalk), use (102 chars):
a := #(10 15 20).
g := a inject:a first into:[:i :e | i gcd:e].
l := a inject:a first into:[:i :e | i lcm:e].

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


text:
Create a C preprocessor
The goal is to create a preprocessor for the C language, as small as possible in terms of source code size in bytes, in your preferred language.
Its input will be a C source file, and its output will be the pre-processed source code.
The items that it will need to be able to process shall be:
Comment removal (line/block), #include directives (by opening files at relative paths and replacing text at the point needed), #define, #undef, #if, #elif, #else, #endif, #ifdef, #ifndef, and defined(). Other C preprocessor directives like #pragmas or #errors may be ignored.
There is no need to calculate arithmetic expressions or comparison operators in #if directives, we assume the expression will evaluate to true as long as it contains an integer other than zero (its main use will be for the defined() directive). Examples of possible input and output follow (possible extra whitespaces in output files were trimmed for better appearance, there is no need for your code to do so). A program able to process the following examples properly will be considered sufficient.
----Input file: foo.c (main file being preprocessed)

#include "bar.h" // Line may or may not exist

#ifdef NEEDS_BAZZER
#include "baz.h"
#endif // NEEDS_BAZZER

#ifdef _BAZ_H_

int main(int argc, char ** argv)
{
    /*  Main function.
        In case that bar.h defined NEEDS_BAZ as true,
        we call baz.h's macro BAZZER with the length of the
        program's argument list. */
    return BAZZER(argc);
}

#elif defined(_BAR_H_)

// In case that bar.h was included but didn't define NEEDS_BAZ.
#undef _BAR_H_
#define NEEDS_BARRER
#include "bar.h"

int main(int argc, char ** argv)
{
    return BARRER(argc);
}

#else

// In case that bar.h wasn't included at all.
int main()
{return 0;}

#endif // _BAZ_H_

----Input file bar.h (Included header)

#ifndef _BAR_H_
#define _BAR_H_

#ifdef NEEDS_BARRER

int bar(int * i)
{
    *i += 4 + *i;
    return *i;
}

#define BARRER(i) (bar(&i), i*=2, bar(&i))

#else
#define NEEDS_BAZZER // Line may or may not exist
#endif // NEEDS_BARRER

#endif // _BAR_H_

----Input file baz.h (Included header)

#ifndef _BAZ_H_
#define _BAZ_H_

int baz(int * i)
{
    *i = 4 * (*i + 2);
    return *i;
}

#define BAZZER(i) (baz(&i), i+=2, baz(&i))

#endif // _BAZ_H_

----Output file foopp.c (no edits)

int baz(int * i)
{
    *i = 4 * (*i + 2);
    return *i;
}

int main(int argc, char ** argv)
{
    return (baz(&argc), argc+=2, baz(&argc));
}

----Output file foopp2.c (with foo.c's first line removed)

int main()
{return 0;}

----Output file foopp3.c (with bar.h's line "#define NEEDS_BAZZER" removed)

int bar(int * i)
{
    *i += 4 + *i;
    return *i;
}

int main(int argc, char ** argv)
{
    return (bar(&argc), argc*=2, bar(&argc));
}

Can you provide input/output samples?

Provide us a test code. It's nearly impossible without examples.

Uh sure, I will. Just be a bit patient as I can't be very fast due to time and workload constraints.

How much of #if needs to be supported? i.e. does the preprocessor need to support expressions with arithmetic, bitwise operations, etc?

ok, example input/output and further explanations added

Sorry for taking so long, but its hard to make such a code.

No problem :) I pretty much figured that out :)

@IsmaelMiguel because C is an obscure language that you could never find examples of online, let alone a Great C Compiler of some sort to verify against... :P

Flex, 1170+4=1174
1170 characters in the flex code + 4 characters for a compilation flag.  To produce an executable, run flex pre.l ; gcc lex.yy.c -lfl.  The entry leaks memory like a sieve and doesn't close included files.  But otherwise, it should be completely functional as per the spec.
%{
#define M malloc
#define X yytext
#define A a=X
#define B(x) BEGIN x;
#define Y YY_CURRENT_BUFFER
*a,*b,**v,**V,**t,**T,i,s=1,o;
g(){t=M(++s);T=M(s);for(i=1;i<s-1;i++)t[i]=v[i],T[i]=V[i];free(v);free(V);v=t;V=T;}
f(){for(i=1;i<s;i++)if(!strcmp(v[i],a))return i;return 0;}
d(y){X[yyleng-y]=0;}
%}
%x D F I
N .*\n
%%
"//".*
"/*"([^\*]|\*[^\/])*"*/"
\"(\\.|[^\\"])*\" ECHO;
^"#include "\"[^\"]*\" d(1),yypush_buffer_state(yy_create_buffer(fopen(X+10,"r"),YY_BUF_SIZE));
^"#define "[^ ]* {B(D)strcpy(a=M(yyleng),X+8);}
<D>" "?{N} {b=M(yyleng);d(1);f(strcpy(b,X+(X[0]==32)))?free(V[i]),V[i]=b:g(),v[s-1]=a,V[s-1]=b;B(0)}
^"#undef "{N} d(1),v[f(A+7)][0]=0;
^"#if defined(".*")\n" h(2,12);
^"#ifdef "{N} h(1,7);
^"#if "{N} {d(1);if(!atoi(X+4))B(F)}
^"#ifndef "{N} {d(1);if(f(A+8))B(F)}
<F>^"#if"{N} o++;
<F>^"#endif"{N} if(!o--)B(++o)
<F>^"#else"{N} if(!o)B(0)
<F>^"#elif defined(".*")\n" if(!o){d(2);if(f(A+14))B(0)}
<F>^"#elif "{N} if(!o){d(1);if(atoi(X+6))B(0)}
<F>{N}
^"#endif"{N}
^"#el"("se"|"if"){N} B(I)
<I>^"#endif"{N} B(0)
<I>{N}
[a-zA-Z_][a-zA-Z_0-9]* printf(f(A)?V[i]:a);
<<EOF>> {a=Y;yypop_buffer_state();if(!Y)exit(0);fclose(a);}
%%
h(x,y){d(x);if(!f(A+y))B(F)}

Some explanation:

a and b are temps to hold strings from the input.  a is also used as the parameter to function f.
v holds the names of macros and V holds the 'V'alues of macros
t and T are 't'emporary holders for when we grow v and V
i is an 'i'ncrementer for loops
s is the 's'ize of the macro array
o is the count of the 'o'pen ifs inside a false conditional
g() 'g'rows the macro arrays
f() 'f'inds a macro with the same value in v as a
d(y) 'd'rops the last y characters from the current input
state D is for inside a 'D'efine
state F is for ignoring a 'F'alse conditional
state I is for 'I'gnoring else/elif after a true conditional was found.

EDIT1: cleaned up many of the memory leaks and implemented file closing
EDIT2: modified code to handle nested macros more correctly
EDIT3: crazy amount of golfing
EDIT4: more golfing
EDIT5: more golfing; I've also noticed that my call to fclose() causes issues on some computers...looking into this.

It works very well so far on most cases... for some reason it throws a segmentation fault when I #include stuff, but I guess this is related to the bug in edit #5. Also it doesn't substitute macros, even though it processes successfully the #if blocks - unless I'm doing something wrong... but in general it looks very good, and it gives a rough idea of what a lexer can do, since I can understand it even in its golfed form. Try to see if the bugs can be fixed, if not it's ok, as the code explains itself well, probably this will be chosen answer as there are no other entries.


text:
Sum of indices of second least significant bit
This is a pure code-golf question.
Input: A non-negative integer n
Output: Sum of the indices of the second least significant set bit in the binary representation of the integers 0...n. If the number doesn't have two set bits then the contribution to the sum should be zero.
Your code should be runnable on a standard linux machine using free software and shouldn't take more than n+1 seconds to run.
Sample answers for n from 0..20
0 0 0 1 1 3 5 6 6 9 12 13 16 18 20 21 21 25 29 30

Here is some sample ungolfed python code.
def get_2nd_least_bit(x):
    sum = 0
    for i in range(0,x.bit_length()):
        sum += (x >> i) & 1
        if sum == 2 :
            return i
    return 0
for x in xrange(20):
    print sum(get_2nd_least_bit(i) for i in xrange(x+1)),

Can you provide an example?

If n=3 I think the output is 1 (using 0 indexing). If n=5 I think it is 3.

What is the limit on n?

The specification certainly needs clarifying, but the question has that wonderful combination of uselessness and just enough patter to encourage searches for shortcuts.

@mniip, do you stand by those figures? I get 0,0,0,1,1,3,5,6,6,9,12,13,16,18,20,21,21,25,29,30,34,...

@PeterTaylor yours looks more correct actually... I'll take the comment down... aand the answer too

k [21 chars]
{+/{(&|0b\:x)1}'!x+1}

Example
{+/{(&|0b\:x)1}'!x+1}[3]
1

{+/{(&|0b\:x)1}'!x+1}[7]
6

{+/{(&|0b\:x)1}'!x+1}[10]
12

{+/{(&|0b\:x)1}'!x+1}[500]
1410

q){sum {(where reverse 0b vs x)[1]}each til x+1}

Where can you get an implementation of K for linux?

@Anush, you can download linux trial version from http://kx.com/software-download.php

18 bytes if you remove the outer function: +/{(&|0b\:x)1}'!1+

GolfScript (31 chars)
,{)2base-1%.,,\`{=}+,1=}%0+{+}*

This takes input on the stack and leaves output on the stack. Online demo which wraps it in a loop to output the first 12 values.
That implementation does the obvious thing of computing the base-2 representation of the integers in range. A more interesting approach, which sadly I haven't been able to golf as far, is to analyse the sequence. It's a sum of indices: let i2(n) be the index of the second LSB of n. We have i2(2^x) = 0 (given as a special case). What can we say about the values which i2 takes between 2^x and 2^(x+1)?

Case 1: 2^x < k < 2^x + 2^(x-1). Then k ^ (2^x + 2^(x-1)) = k - 2^(x-1). If i2(k - 2^(x-1)) < x-1 then i2(k) = i2(k - 2^(x-1)); otherwise i2(k) = x = 1 + i2(k - 2^(x-1)).
Case 2: k = 2^x + 2^(x-1). Obviously i2(k) = x since there are two bits set.
Case 3: 2^x + 2^(x-1) < k < 2^(x+1) has bit x-1 set and at least one less significant bit set, so i2(k) = i2(k - 2^x).

In other words: the sequence of indices between consecutive powers of two can be found by splicing together three sequences: the previous sequence under the substitution s/x-1/x/; the sequence [x]; and the previous sequence unmodified.

[]
[] + [1] + [] = [1]
[2] + [2] + [1] = [2 2 1]
[3 3 1] + [3] + [2 2 1] = [3 3 1 3 2 2 1]
[4 4 1 4 2 2 1] + [4] + [3 3 1 3 2 2 1] = [4 4 1 4 2 2 1 4 3 3 1 3 2 2 1]
etc.

This leads to (40 chars)
([]{,2$<}{..0+0=:x+{.x=+}%\+}/1,*<0+{+}*

(Note for GS aficionados: a rare use for unfold!)

I'm trying to run online demo with different argument and just curious: is it real run time duration (and hence limit) > 5 sec run time for n > 12?

@VadimR, that server's runtime is quite inconsistent. I chose 12 arbitrarily. On my computer it takes less than 1 second for n = 20.

J (and mathematics), way too much (aka. 45 chars), cubic memory and terrible runtime
+/,(*v>(2&^*1+a*2:)+/2^i.)"0]a=.i.v=.".1!:1]1

If I wanted to aim for length, I could of course do it the obvious, straightforward way and get something considerably shorter... however, I found it more interesting to investigate the properties of "index of second least significant set bit".
The J program above is an instance of the formula derived below.  The idea is to build a huge table of numbers per bit index, then filter out those below the number we seek, then multiply by the bit index, then sum it all up.

So, I started with the slightly different case "index of the least significant set bit" (LSSB), because it's always best to start simple when looking for patterns...  I plotted the index of the LSSB for numbers [0..40]:
          1111111111222222222233333333334
01234567890123456789012345678901234567890
-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0   =  2k + 1
  1   1   1   1   1   1   1   1   1   1    =  4k + 2
    2       2       2       2       2      =  8k + 4
        3               3               3  = 16k + 8
                4
                                5

(Here, - means N/A.)  Well, that's a very obvious pattern.  Joining the cases together we get 2^v * (2k + 1) for row v, for integers k (or, 2^v * m for odd m, if you prefer).  This is sequence A007814 in OEIS.
Okay, so, back to our real case of the second least significant set bit (2LSSB).  Let's do a similar plot for this case and see if there's any pattern here too, and if so, how it relates to the previous pattern.
          1111111111222222222233333333334
01234567890123456789012345678901234567890
--- -   -       -               -
   1   1   1   1   1   1   1   1   1   1
     22      22      22      22      22
         33 3            33 3
                 44 4   4
                                 55 5   5

Well... huh.  That looks a bit strange, but there's still some sort of repetition going on.  Let's take a look at what numbers get assigned which indices.
0: 0 1 2 4 8 16 32             ...  2^k
1: 3 7 11 15 19 23 27 31 35 39 ...  4k +  2 + {1}           =  2*(2k + 1) + 2^{0}
2: 5 6 13 14 21 22 29 30 37 38 ...  8k +  4 + {1,2}         =  4*(2k + 1) + 2^{0,1}
3: 9 10 12 25 26 28            ... 16k +  8 + {1,2,4}       =  8*(2k + 1) + 2^{0,1,2}
4: 17 18 20 24                 ..? 32k + 16 + {1,2,4,8}     = 16*(2k + 1) + 2^{0,1,2,3}
5: 33 34 36 40                 ..? 64k + 32 + {1,2,4,8,16}  = 32*(2k + 1) + 2^{0,1,2,3,4}

Okay, yeah, definitely a pattern.  The general case here is 2^v * (2k + 1) + 2^j, j < v.  While we're at it, let's do one more just to see how this all generalises for the n:th least significant set bit.
                                                                                111111111111111111111111111111
          111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999000000000011111111112222222222
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
 01 012 4       012 4   8      16                               012 4   8      16              32   ...
  012   012 4   8               012 4   8      16              32                                   ...
------- --- -   --- -   -       --- -   -       -               --- -   -       -               -                                       =   2^k + 2^l, l < k                                 0
                                                                                1
       2       2       2       2       2       2       2       2       2       2       2       2       2       2       2       2        =   8*k +  4 + {3}                                   2
           3 33            3 33            3 33            3 33            3 33            3 33            3 33            3 33         =  16*k +  8 + {3,5,6}                               3
                   4 44  44 4                      4 44  44 4                      4 44  44 4                      4 44  44 4           =  32*k + 16 + {3,5,6,9,10,12}                       4
                                   5 55  55 5    55 5   5                                          5 55  55 5    55 5   5               =  64*k + 32 + {3,5,6,9,10,12,17,18,20,24}           5
                                                                   6 66  66 6    66 6   6        66 6   6       6                       = 128*k + 64 + {3,5,6,9,10,12,17,18,20,24,...}       6

Phew.  40 digits didn't cut it for finding patterns here, so I had to extend it a bit.  Sorry about that horizontal scrollbar.  Here's the table to the far right again, to spare you from having to scroll back and forth.
   2^k + 2^l, l < k                                 0
                                                    1
   8*k +  4 + {3}                                   2
  16*k +  8 + {3,5,6}                               3
  32*k + 16 + {3,5,6,9,10,12}                       4
  64*k + 32 + {3,5,6,9,10,12,17,18,20,24}           5
 128*k + 64 + {3,5,6,9,10,12,17,18,20,24,...}       6

Huh.  That's weird, what are those numbers?  They're certainly not powers of two...  maybe I should've been able to guess it from the earlier two tables, but instead I went to OEIS and found it's actually the set of sums of two distinct powers of two.  So it seems like a qualified guess to generalise this by taking the sum of n distinct powers of two for the index of the n:th least significant set bit.  All in all, the final expression looks like so:

The first sequence which you say wasn't in the OEIS looks like A007814 to me - or is that not the sequence you were looking for?

@Peter oh, that's the sequence.  I don't know why I didn't find it yesterday, I must've had a typo somewhere I suppose.

Ruby, 64
Here's a regex-based solution.  I hope it's correct, the spec could use some test cases...
p (0..gets.to_i).inject{|s,n|n.to_s(2)=~/10*10*$/?s+$&.size-1:s}

Examples:
>echo 3 | ruby sum-of-indices.rb
1
>echo 7 | ruby sum-of-indices.rb
6
>echo 10 | ruby sum-of-indices.rb
12
>echo 500 | ruby sum-of-indices.rb
1410

Postscript, 179
Not to compete in golf, just for fun. I like it, that 1's indexes (which are post-match lengths in a string scanned left to right starting with most significant bits) are accumulated on stack and so to find second least significant, one operand is popped, next added to sum, the rest are discarded (stack cleared).
/s 0 def 0 1(%stdin)(r)file token pop {2 32 string cvrs mark exch {(1)search{pop pop dup}{pop exit}ifelse}loop counttomark 2 ge{pop length s add/s exch def}if cleartomark}for s =

Un-golfed, and with timer attached:
/s 0 def
0 1
(%stdin) (r) file
token pop
realtime 4 1 roll
{
    2 32 string cvrs
    mark exch
    {
        (1) search
        {pop pop dup}{pop exit}ifelse
    } loop
    counttomark 2 ge {pop length s add /s exch def} if
    cleartomark
} for
s =
realtime
(Time elapsed, s: )=
exch sub 1000 div =

And:
echo 10 | gs -q -dBATCH sum.ps
12
Time elapsed, s:
0.0

echo 500 | gs -q -dBATCH sum.ps
1410
Time elapsed, s:
0.0

echo 1000000 | gs -q -dBATCH sum.ps
2999655
Time elapsed, s:
3.218

How do you run this code in practice?

@Anush, code saved as sum.ps, then run, see above, echo 10 | gs -q -dBATCH sum.ps (gswin32 on Windows).

@Anush, sorry, it's gswin32c actually.

Smalltalk (Smalltalk/X) (105 chars)
(0 to:20)
    injectAndCollect:0
    into:[:sumSoFar :n |
            sumSoFar +
            (([(n clearBit:n lowBit) lowBit] ifError:0) - 1 max:0)
         ]

-> 0 0 0 1 1 3 5 6 6 9 12 13 16 18 20 21 21 25 29 30 34
injectAndCollect:into: is not part of Ansi Smalltalk, though.

JavaScript, 69 68
for(s=k=prompt(r=0);k--;r=k&k+1)for(s-=!r;r*!(r&2);r/=2)s++;alert(s)

The approach is to strip the lowest bit (the result is stored in r) then count the trailing zeroes.
Longer alternate, 79 chars
for(k=prompt(s=0);k--;s+=/.(0*)$/.exec((k&k+1).toString(2))[1].length);alert(s)

The takes the r from above, converts it to a binary string, and uses a regular expression to count the trailing zeroes. I include it because I like the idea of doing the counting with string processing.

32-bit x86 assembly code, 22 bytes
Accepts input in ecx register, output is in eax register.
00000000 33 c0    xor   eax, eax
00000002 e3 11    jecxz 00000015
00000004 51       push  ecx
00000005 0f bc d1 bsf   edx, ecx
00000008 0f b3 d1 btr   ecx, edx
0000000B 0f bc d1 bsf   edx, ecx
0000000E 74 02    je    00000012
00000010 03 c2    add   eax, edx
00000012 59       pop   ecx
00000013 e2 ef    loop  00000004
00000015 c3       ret


text:
3 and 5 Litre Jug Puzzle
You may have seen this one in Die Hard: With a Vengeance... This question is based on the famous 3 and 5 Litre Jug Puzzle, but with a slightly different slant.
Golf up some code that when given an integer between 1 and 100 will provide you with the quickest instructions to measure out into a tank, the corresponding number of litres of water from a fountain, using a 3 litre jug and a 5 litre jug.
There are no gradations on either of the jugs; the fountain is abundant in supply of water, and the tank is assumed to be emptied out upon the start of each execution of the code.
You cannot access water from the tank once it goes into the tank.
The format of execution is as follows:
Input:
4 for example.
Output
Output each numbered step, as shown, followed by a tally of the volumes of the 5L jug, the 3L jug and the tank. Tally format also shown below. The number of steps must also be outputted at the end of the steps.
1) Fill 5L jug
5L: 5, 3L: 0, T: 0
2) Pour from 5L jug into 3L jug
5L: 2, 3L: 3, T: 0
3) Empty 3L jug
5L: 2, 3L: 0, T: 0
4) Pour from 5L jug into 3L jug
5L: 0, 3L: 2, T: 0
5) Fill 5L jug
5L: 5, 3L: 2, T: 0
6) Pour from 5L jug into 3L jug
5L: 4, 3L: 3, T: 0
7) Pour from 5L jug into tank
5L: 0, 3L: 3, T: 4
Volume measured out in 7 turns
Example 2
Input: 8
Output:
1) Fill 5L jug
5L: 5, 3L: 0, T: 0
2) Pour from 5L jug into tank
5L: 0, 3L: 0, T: 5
3) Fill 3L jug
5L: 0, 3L: 3, T: 5
4) Pour from 3L jug into tank
5L: 0, 3L: 0, T: 8
Volume measured out in 4 turns
Conventions

Fill xL jug - fills the associated jug to the top from the fountain
Empty xL jug - empties the contents of the associated jug into the fountain
Pour from xL jug into yL jug - Pours the contents of the xL jug into the yL jug
Pour from xL jug into tank - Pours the contents of the xL jug into the tank

Shortest code wins.

possible duplicate of Water-Bucket problem

@Howard, the old question is ill-specified (has no winning criteria) and was abandoned, so I think that this one is better and should not be closed.

Call me crazy, but isnt the optimal solution going to be 1. Add as many 5L as possible, 2. Add 3L if needed, 3. Add an already solved 2L or 1L portion as required?

@LegoStormtroopr When it all boils down, true. But I'm expecting it to be code-golfed accordingly.

@LegoStormtroopr I thought that too, but aren't 6 and 9 counterexamples?

@Chron Good point, I hadn't thought of that.

What do you exactly mean by "quickest instructions". Is filling a 6L tank with (5L + 1L) accepted? Or it should be filled with (3L + 3L). I'm asking this because some answers down there use the first approach (greedy filling with 5L then 3L then 2L then 1L)

I'm happy to work with either @belisarius. In the case of 6L a greedy 5L fill process followed by a 4/3/2/1L woudl be fine; or a greedy 3L fill. I think I'm going to be flexible on the approach... If you can provide code that can give the solution, fantastic...

Ruby, 407 376 365 331 324 323
This is getting kind of hard to read...
x=y=n=d=0
g=gets.to_i
"#{[43435,102,t=45,t,12,t,12,t,t][g+~d]||12}".chars{|c|n+=1
puts [eval(["x-=t=[3-y,x].min;y+=t"+t=";'Pour from 5L jug into 3L jug'","x=5;'Fill 5L jug'","d+=x;x=0"+t.sub(/3.+/,"tank'")][c.ord%3].tr t='35xy',c<?3?t:'53yx'),"5L: #{x}, 3L: #{y}, T: #{d}"]}while g>d
$><<"Volume measured out in #{n} turns"

Takes input on STDIN.  Example run for N=10:
Fill 5L jug
5L: 5, 3L: 0, T: 0
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 5
Fill 5L jug
5L: 5, 3L: 0, T: 5
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 10
Volume measured out in 4 turns

"This is getting kind of hard to read..." - Dude, ain't that the point of code golf...? ;)

@WallyWest Nope. We have an [obfuscation] tag for those! My humble opinion would be that of two codegolf solutions of the same length, the most readable one would be the best.

@MrLister Fair enough, but sometimes obfuscation is the only way to achieve the desired shrinkage...

T-SQL 2012: 1410 1302
Another quixotic attempt at a question in SQL, but this one offered an enjoyable  opportunity to play with some of the new window function options in version 2012. In addition, it exploits recursive CTEs, which may be nothing impressive in most programming languages, but recursion in SQL is like switching from horse and buggy to a Ferrari.
The engine at the heart of this is in lines 5-12, which uses a recursive CTE and a window function to build a table of most of the numbers needed to solve the problem. Note in particular the test for 3, 4, 6, or 9, which ensures an optimal approach to the solution by 3s from those numbers onward. (Technically, it's a tie for 4 between the 3-1 approach and the 2-2, but doing it this way golfed me a lot of characters.) Then it's a simple matter to join to a lookup table of the optimal steps for different chunks of the problem and use another window function to properly number the steps.
If you don't have MS SQL lying around, play with it on SQLFiddle.
DECLARE @i INT=42,@l VARCHAR(9)='L jug ',@k VARCHAR(99)='into tank
5L: 0, 3L: 0, T: ',@o VARCHAR(99)='
5L: 5, 3L: 0, T: ',@n CHAR(1)='
',@5 VARCHAR(99)=') Pour from 5',@3 VARCHAR(99)=') Pour from 3'
;WITH t AS (SELECT @i i,(@i-@i%5)%5 j
UNION ALL
SELECT i-5,(i-i%5)%5+5 FROM t WHERE i>=5 AND i NOT IN(6,9)
UNION ALL
SELECT i-3,3FROM t WHERE i in(3,4,6,9)
UNION ALL
SELECT i-i,i FROM t WHERE i<3 AND i>0)
SELECT t.i,t.j,v.s,ROW_NUMBER()OVER(PARTITION BY t.j ORDER BY t.i DESC)x,SUM(t.j)OVER(ORDER BY t.i DESC ROWS UNBOUNDED PRECEDING)y INTO #q FROM(VALUES(1,5),(2,3),(3,2),(5,2))v(i,s) JOIN t ON t.j = v.i
SELECT z.b FROM(SELECT ROW_NUMBER()OVER(ORDER BY q.i DESC,w.s)a,CAST(ROW_NUMBER()OVER(ORDER BY q.i DESC,w.s)AS VARCHAR)+w.v+CAST(y-CASE WHEN q.s!=w.s THEN q.j ELSE 0 END AS VARCHAR)b
FROM(VALUES(5,1,') Fill 5'+@l+@o),(5,2,@5+@l+@k),(3,1,') Fill 3'+@l+@n+'5L: 0, 3L: 3, T: '),(3,2,@3+@l+@k),(2,1,') Fill 5'+@l+@o),(2,2,@5+@l+' into 3'+@l+@n+'5L: 2, 3L: 3, T: '),(2,3,@5+@l+@k),(1,1,') Fill 3'+@l+@n+'5L: 0, 3L: 3, T: '),(1,2,@3+@l+'into 5'+@l+@n+'5L: 3, 3L: 0, T: '),(1,3,') Fill 3'+@l+@n+'5L: 3, 3L: 3, T: '),(1,4,@3+@l+'into 5'+@l+@n+'5L: 5, 3L: 1, T: '),(1,5,@3+@l+'into tank'+@o))w(i,s,v)JOIN #q q ON w.i=q.j
UNION
SELECT 99,'Volume measured out in '+CAST(COUNT(*)AS VARCHAR)+' turns'
FROM #q)z

Results for the input 42:
1) Fill 5L jug
5L: 5, 3L: 0, T: 0
2) Pour from 5L jug into tank
5L: 0, 3L: 0, T: 5
3) Fill 5L jug
5L: 5, 3L: 0, T: 5
4) Pour from 5L jug into tank
5L: 0, 3L: 0, T: 10
5) Fill 5L jug
5L: 5, 3L: 0, T: 10
6) Pour from 5L jug into tank
5L: 0, 3L: 0, T: 15
7) Fill 5L jug
5L: 5, 3L: 0, T: 15
8) Pour from 5L jug into tank
5L: 0, 3L: 0, T: 20
9) Fill 5L jug
5L: 5, 3L: 0, T: 20
10) Pour from 5L jug into tank
5L: 0, 3L: 0, T: 25
11) Fill 5L jug
5L: 5, 3L: 0, T: 25
12) Pour from 5L jug into tank
5L: 0, 3L: 0, T: 30
13) Fill 5L jug
5L: 5, 3L: 0, T: 30
14) Pour from 5L jug into tank
5L: 0, 3L: 0, T: 35
15) Fill 5L jug
5L: 5, 3L: 0, T: 35
16) Pour from 5L jug into tank
5L: 0, 3L: 0, T: 40
17) Fill 5L jug
5L: 5, 3L: 0, T: 40
18) Pour from 5L jug  into 3L jug
5L: 2, 3L: 3, T: 40
19) Pour from 5L jug into tank
5L: 0, 3L: 0, T: 42
Volume measured out in 9 turns

Edit:
Golfed out a decent score improvement by

eliminating an unnecessary +5 in the first row of the CTE, and the WHERE clause it necessitated
in-lining the VALUES tables, saving costly DECLARE statements
remembering to convert Windows double-byte CRLFs to Unix style this time.

+1 for bravery, dude... Very impressive and thanks for the MS SQL fiddle link!

Haha, thanks man! I actually believed this one might be winnable when I started and had the recursive core query. But even with extensive string golfing, the verbosity of adding all the necessary text doomed my final solution.  :)

If I could do a "most-creative" bounty, you'd get it...

+1 for making me LOL. T-SQL is certainly an odd club to carry in your code-golf bag.

Javascript: 481
First attempt at golfing, advice appreciated
n=["3L jug","5L jug","tank"];l=[0,0,0];t=[3,5,0];h=0;c=console;function e(d){l[d]=t[d];c.log(++h+") Fill "+n[d]);k()}function m(d,g){s=l[d];f=l[g];b=s+f>t[g];l[g]=b?t[g]:f+s;l[d]=b?s-(t[g]-f):0;c.log(++h+") Pour from "+n[d]+" into "+n[g]);k()}function k(){c.log("5L: "+l[1]+", 3L: "+l[0]+", T: "+l[2])}a=prompt();for(t[2]=a;4<a;)e(1),m(1,2),a-=5;2<a&&(e(0),m(0,2),a-=3);1<a&&(e(1),m(1,0),m(1,2),a=0);0<a&&(e(0),m(0,1),e(0),m(0,1),m(0,2));c.log("Volume measured out in "+h+" turns")

It messes up with some numbers because it doesn't check if it's better to pour 3 or 5, example: 9 gives 9 turns instead of 6, I might fix it later
Paste it in console
From 553 to 481 thanks to @WallyWest

You could try:
n=["3L jug","5L jug","tank"];l=[0,0,0];t=[3,5,0];h=0;c=console;function e(d){l[d]=t[d];c.log(++h+") Fill "+n[d]);k()}function m(d,g){s=l[d];f=l[g];b=s+f>t[g];l[g]=b?t[g]:f+s;l[d]=b?s-(t[g]-f):0;c.log(++h+") Pour from "+n[d]+" into "+n[g]);k()}function k(){c.log("5L: "+l[1]+", 3L: "+l[0]+", T: "+l[2])}a=prompt();for(t[2]=a;4<a;)e(1),m(1,2),a-=5;2<a&&(e(0),m(0,2),a-=3);1<a&&(e(1),m(1,0),m(1,2),a=0);0<a&&(e(0),m(0,1),e(0),m(0,1),m(0,2));c.log("Volume measured out in "+h+" turns")
for 481 characters...

@WallyWest thanks, didn't think about using logical operators instead of ifs

Java, 610
class X{int n,c=0,t=0;public void static main(String[]a){n=Integer.parseInt(a[0]);String s,b,f,k,m,u;b="5L";s="3L";k="tank";u="Fill %s jug\n5L: %d, 3L: %d, T: %d";m="\nPour from %s jug into %s\n5L: %d, 3L: %d, T: %d";f=u+m;for(;n>4;)z(f,2,5,b,5,0,t,b,k,0,0,t+=5);while(n!=0){if(n==1)z(f+f+m,5,1,s,0,3,t,s,b,3,0,t,s,3,3,t,s,b,5,1,t,s,k,5,0,t+1);if(n==3)z(f,2,3,s,0,3,t,s,k,0,0,t+3);z(f+m,3,2,b,5,0,t,b,s,2,3,t,b,k,0,3,t+=2);if(n==2)z("Empty 3L jug\n5L: 0, 3L: 0,T: %d",1,0,t)}z("Volume measured out in %d turns",0,0,c)}void z(String s,int o,int w,Object...a){c+=o;n-=w;System.out.println(String.format(s,a))}}

I took the solution of Sumedh and golfed it. I wanted to put it in the comments but my reputation isn't enough :( . It's a 40% less, I think it should at least be shared. Still far from first though...
Here is ungolfed:
    class X{
    int n,c=0,t=0;
    public void static main(String[] a){
        n=Integer.parseInt(a[0]);
        String s,b,f,k,m,u;
        b="5L";
        s="3L";
        k="tank";
        u="Fill %s jug\n5L: %d, 3L: %d, T: %d";
        m="\nPour from %s jug into %s\n5L: %d, 3L: %d, T: %d";
        f=u+m;
        for(;n>4;)z(f,2,5,b,5,0,t,b,k,0,0,t+=5);
        while(n!=0)
        {
            if(n==1)z(f+f+m,5,1,s,0,3,t,s,b,3,0,t,s,3,3,t,s,b,5,1,t,s,k,5,0,t+1);
            if(n==3)z(f,2,3,s,0,3,t,s,k,0,0,t+3);
            z(f+m,3,2,b,5,0,t,b,s,2,3,t,b,k,0,3,t+=2);
            if(n==2)z("Empty 3L jug\n5L: 0, 3L: 0,T: %d",1,0,t);
        }
        z("Volume measured out in %d turns",0,0,c);
    }
    void z(String s,int o, int w,Object... a){
        c+=o;
        n-=w;
        System.out.println(String.format(s,a));
    }
}

NB: it works only on the first run. Rerun it and the result will be wrong (due to a global variable).
The following version is safe, but we lose 2 char, going from 610 to 612:
    class X{
    int n,c,t;
    public void static main(String[] a){
        n=Integer.parseInt(a[0]);
        String s,b,f,k,m,u;
        t=c=0;
        b="5L";
        s="3L";
        k="tank";
        u="Fill %s jug\n5L: %d, 3L: %d, T: %d";
        m="\nPour from %s jug into %s\n5L: %d, 3L: %d, T: %d";
        f=u+m;
        for(;n>4;)z(f,2,5,b,5,0,t,b,k,0,0,t+=5);
        while(n!=0)
        {
            if(n==1)z(f+f+m,5,1,s,0,3,t,s,b,3,0,t,s,3,3,t,s,b,5,1,t,s,k,5,0,t+1);
            if(n==3)z(f,2,3,s,0,3,t,s,k,0,0,t+3);
            z(f+m,3,2,b,5,0,t,b,s,2,3,t,b,k,0,3,t+=2);
            if(n==2)z("Empty 3L jug\n5L: 0, 3L: 0,T: %d",1,0,t);
        }
        z("Volume measured out in %d turns",0,0,c);
    }
    void z(String s,int o, int w,Object... a){
        c+=o;
        n-=w;
        System.out.println(String.format(s,a));
    }
}

Sample output for N=69:
Fill 5L jug
5L: 5, 3L: 0, T: 0
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 5
Fill 5L jug
5L: 5, 3L: 0, T: 5
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 10
Fill 5L jug
5L: 5, 3L: 0, T: 10
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 15
Fill 5L jug
5L: 5, 3L: 0, T: 15
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 20
Fill 5L jug
5L: 5, 3L: 0, T: 20
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 25
Fill 5L jug
5L: 5, 3L: 0, T: 25
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 30
Fill 5L jug
5L: 5, 3L: 0, T: 30
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 35
Fill 5L jug
5L: 5, 3L: 0, T: 35
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 40
Fill 5L jug
5L: 5, 3L: 0, T: 40
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 45
Fill 5L jug
5L: 5, 3L: 0, T: 45
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 50
Fill 5L jug
5L: 5, 3L: 0, T: 50
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 55
Fill 5L jug
5L: 5, 3L: 0, T: 55
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 60
Fill 5L jug
5L: 5, 3L: 0, T: 60
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 65
Fill 5L jug
5L: 5, 3L: 0, T: 65
Pour from 5L jug into 3L
5L: 2, 3L: 3, T: 65
Pour from 5L jug into tank
5L: 0, 3L: 3, T: 67
Empty 3L jug
5L: 0, 3L: 0,T: 67
Fill 5L jug
5L: 5, 3L: 0, T: 67
Pour from 5L jug into 3L
5L: 2, 3L: 3, T: 67
Pour from 5L jug into tank
5L: 0, 3L: 3, T: 69
Volume measured out in 33 turns

Java: 984
Here's the code
class X{public static void main(String[] s){int n=Integer.parseInt(s[0]);int t=0;int c=0;while(n>4){n-=5;System.out.println("Fill 5L jug\n5L: 5, 3L: 0, T: "+t+"\nPour from 5L jug into tank\n5L: 0, 3L: 0, T: "+(t+5));t+=5;c+=2;}while(n!=0){switch(n){case 1:System.out.println("Fill 3L jug\n5L: 0, 3L: 3, T: "+t+"\nPour from 3L jug into 5L jug\n5L: 3, 3L: 0, T: "+t+"\nFill 3L jug\n5L: 3, 3L: 3, T: "+t+"\nPour from 3L jug into 5L jug\n5L: 5, 3L: 1, T: "+t+"\nPour from 3L jug into tank\n5L: 5, 3L: 0, T: "+(t+1));n=0;c+=5;break;case 3:System.out.println("Fill 3L jug\n5L: 0, 3L: 3, T: "+t+"\nPour from 3L jug into tank\n5L: 0, 3L: 0, T: "+(t+3));n=0;c+=2;break;default:System.out.println("Fill 5L jug\n5L: 5, 3L: 0, T: "+t+"\nPour from 5L jug into 3L jug\n5L: 2, 3L: 3, T: "+t+"\nPour from 5L jug into tank\n5L: 0, 3L: 0, T: "+(t+2));n-=2;c+=3;t+=2;if(n==2){System.out.println("Empty 3L jug\n5L: 0, 3L: 0,T: "+t);c++;}break;}}System.out.println("Volume measured out in "+c+" turns");}}

Input is from command line. for example: java X 4

I cant comment anywhere else, so I'm commenting here.
@Lego Stormtroopr, there's an alternate optimum solution, where for 4L remaining, you can do same as that for 2L(3 steps) then empty 3L jug, & then repeat for remaining 2L, thus making it complete in 7 steps....which is same for your solution where 4L is divided into: 3L into tank(2 steps) & a 5 step method for remaining 1L.

@Chron,does your code work for values of N, where N%5 is 1 or 4 ?   I dont understand ruby, thats why I couldnt test it myself...

it should, for example have a look here at N=11: http://ideone.com/3ZDuOS You can hit edit in the top-left and change STDIN to other values if you want to check.

Wow, you've got more optimum solution than mine....how do you decide when to stop 5L & use 3L instead? I mean, if input is 81,then you get upto 75L using 5L, & then use 3L. if ip is 89, then 5L is used upto 80L, & remaining are 3L.

Save some chars: main(String[]s), int n=Integer.parseInt(s[0]),t=0,c=0;, java.io.PrintStream q=System.out;. Also, it may be possible to write the first while as a one or two characters shorter for. Further, your Strings are repetitive, you might try to store repetitive parts in variables or create functions that build them using only one prefab String.

Yes,I can definitely do that, but even then, my answer wouldnt even be less than twice the shortest answer, thats why I didnt bother editing my answer.But just for the record,using Chron's logic, & by reducing few characters like you've said, my answer has come into 600's

Oh Chron, something I found just now, your code doesnt work for 1 & 4.

If you have a shorter version, go ahead and edit your post to include it - doesn't hurt anyone. You currently have the shortest Java version as is. :-)

Python 2.7 - 437
Not the shortest code, but I think this is the most optimal way of solving this.
As I stated in the comments, the most optimal way to calculate this:

Take as many chunks of 5L as possible - divmod(amount,5). This will give you one of 4,3,2,1 as the remainder.
Take 3 (if possible) from the remainder.
Which leaves either 1 or 2 as the remainder. Use the optimal solution for either which can be known ahead of time as:

1L, 5 steps : 3L -> 5L, 3L -> 5L, leaving 1L in the 3L, 3L (holding 1L) -> tank
2L, 3 steps : 5L -> 3L, leaves 2L in the 5L, 5L (holding 2L) -> tank

The code:
j,T="%dL jug","tank"
A="\n5L: %d, 3L: %d, T: %d"
F,P="Fill "+j+A,"Pour from "+j+" into %s"+A
f,r=divmod(input(),5)
o,t=f*5,[]
for i in range(f):o+=[F%(5,5,0,5*i),P%(5,T,0,0,5*i+5)]
if r>2:o+=[F%(3,0,3,t),P%(3,T,0,0,t+3)];r-=3;t+=3
if r==2:o+=[F%(5,5,0,t),P%(5,j%3,2,3,t),P%(5,T,0,3,t+2)]
if r==1:o+=[F%(3,0,3,t),P%(3,j%5,3,0,t),F%(3,3,3,t),P%(3,j%5,5,1,t),P%(3,T,5,0,t+1)]
print"\n".join(o),'\n',"Volume measured out in %d turns"%len(o)

And an output for 4L in 7 steps:
Fill 3L jug
5L: 0, 3L: 3, T: 0
Pour from 3L jug into tank
5L: 0, 3L: 0, T: 3
Fill 3L jug
5L: 0, 3L: 3, T: 3
Pour from 3L jug into 5L jug
5L: 3, 3L: 0, T: 3
Fill 3L jug
5L: 3, 3L: 3, T: 3
Pour from 3L jug into 5L jug
5L: 5, 3L: 1, T: 3
Pour from 3L jug into tank
5L: 5, 3L: 0, T: 4
Volume measured out in 7 turns

You are assigning an int to o and then trying to add a list. I think you meant to assign o,t=[],f*5 on line 5.

Lose those for, range, and if statements and you can get it down to 399 on one line:  j,T="%dL jug","tank";A="\n5L: %d, 3L: %d, T: %d";F,P="Fill "+j+A,"Pour from "+j+" into %s"+A;f,r=divmod(input(),5);t,o=f5,[];o=[F%(5,5,0,5i),P%(5,T,0,0,5i+5)]f+[F%(3,0,3,t),P%(3,T,0,0,t+3)](r>2)+[F%(5,5,0,t),P%(5,j%3,2,3,t),P%(5,T,0,3,t+2)](r==2)+[F%(3,0,3,t),P%(3,j%5,3,0,t),F%(3,3,3,t),P%(3,j%5,5,1,t),P%(3,T,5,0,t+1)]*(r in[1,4]);print"\n".join(o),"\nVolume measured out in %d turns"%len(o)

Impressive manipulation... @psion5mx I didn't think this kind of programming was possible on Python? No range, recursion or if statements?

The power of lists. Multiplying a list by an integer replaces the 'loops'. Multiplying by a boolean replaces the 'ifs'.

Also - I managed to get it down to a single space (outside of quotes), but could eliminate all spaces at the cost of a character by replacing (r in[1,4]) with (r%5in[1,4]) in this case.

Your code crashes on line o+=[F....]. o is an integer.

Smalltalk (Smalltalk/X), 568 560 516
input in n:
    T:=j:=J:=c:=0.m:={'Pour from'.' into'.' 3L jug'.' 5L jug'.[j:=j+3.'Fill'].[J:=J+5.'Fill'].[t:=j.j:=0.''].[t:=J.J:=0.''].[r:=j min:5-J.j:=j-r.J:=J+r.''].[r:=J min:3-j.J:=J-r.j:=j+r.''].[T:=T+t.' into tank'].[c:=c+1.'\5L: %1 3L: %2 T: %3\'bindWith:J with:j with:T].['Volume measured out in %1 turns'bindWith:c]}.[n>=0]whileTrue:[s:=n.n:=0.(s caseOf:{0->[n:=-1.'<'].1->'42;02813;42;02813;062:;'.2->'53;03912;073:;'.3->'42;062:;'.4->[n:=1.'42;062:;']}otherwise:[n:=s-5.'53;073:;'])do:[:c|(m at:c-$/)value withCRs print]]

boy this is definitely the most obfuscated program I've ever written...
Edit: Some other Smalltalks may not allow autodeclared workspace variables and you'll have to prepend declarations. Also bindWith: may be different (expandWith:'<p>').
sample output for n=17:
Fill 5L jug
5L: 5, 3L: 0, T: 0
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 5
Fill 5L jug
5L: 5, 3L: 0, T: 5
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 10
Fill 5L jug
5L: 5, 3L: 0, T: 10
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 15
Fill 5L jug
5L: 5, 3L: 0, T: 15
Pour from 5L jug into 3L jug
5L: 2, 3L: 3, T: 15
Pour from 5L jug into tank
5L: 0, 3L: 3, T: 17
Volume measured out in 9 turns

C, 567 609
#define r printf
#define l r("5L: %d, 3L: %d, T: %d\n", a, b, T);
#define j(x,y,z,w) r("%d) "#x" %dL jug\n", i++, y),z=w,l
#define e j(Empty,3,b,0)
#define f j(Fill,5,a,5)
#define g j(Fill,3,b,3)
#define o(x,y,z,w) r("%d) Pour from %dL jug into "x"\n", i++, y,z),w;l
#define t(x,y) T+=x,o("tank",y,0,x=0)
#define p(x) o("%dL jug",5,3,(a-=x,b+=x))
int N,T,i;q(x){int a=0,b=0;switch(x){case 5:f t(a,5) break;case 3:g t(b,3) break;case 1:case 2:case 4:f if(x-2){e p(2)f p(1)if(x-4){e p(3)}}t(a,5)}N-=x;}main(){T=0,i=1,scanf("%d",&N);while(N>5)q((N-6)&&(N-9)?5:3);q(N);r("Volume measured out in %d turns",i-1);}

previous invalid version:
#define r printf
#define l r("5L: %d, 3L: %d, T: %d\n", a, b, T);
#define j(x,y,z,w) r("%d) "#x" %dL jug\n", i++, y),z=w,l
#define e j(Empty,3,b,0)
#define f j(Fill,5,a,5)
#define g j(Fill,3,b,3)
#define o(x,y,z,w) r("%d) Pour from %dL jug into "x"\n", i++, y,z),w;l
#define t o("tank",5,0,a=0)
#define p(x) o("%dL jug",5,3,(a-=x,b+=x))
int N,T,i;q(x){int a=0,b=0;switch(x){case 5:f t break;case 3:g t break;case 1:case 2:case 4:f if(x-2){e p(2)f p(1)if(x-4){e p(3)}}t}N-=x;}main(){T=0,i=1,scanf("%d",&N);while(N>5)q(5);q(N);r("Volume measured out in %d turns",i-1);}

and here is the code degolfed:
#define r printf
#define l r("5L: %d, 3L: %d, T: %d\n", a, b, T);
#define j(x,y,z,w) r("%d) "#x" %dL jug\n", i++, y),z=w,l
#define e j(Empty,3,b,0)
#define f j(Fill,5,a,5)
#define g j(Fill,3,b,3)
#define o(x,y,z,w) r("%d) Pour from %dL jug into "x"\n", i++, y,z),w;l
#define t o("tank",5,0,a=0)
#define p(x) o("%dL jug",5,3,(a-=x,b+=x))
int N,T,i;
q(x)
{
    int a=0,b=0;
    switch(x)
    {
        case 5:
            f
            t
            break;
        case 3:
            g
            t
            break;
        case 1:
        case 2:
        case 4:
            f
            if(x-2)
            {
                e
                p(2)
                f
                p(1)
                if(x-4)
                {
                    e
                    p(3)
                }
            }
            t
    }
    N-=x;
}
main()
{
    T=0,i=1,scanf("%d",&N);
    while(N>
    5)q(5);
    q(N);
    r("Volume measured out in %d turns",i-1);
}

This doesn't give the optimal solution for 9 (8 turns, should be 6 - fill and empty the 3L 3 times).

Also doesn't work at all for an input of 1.

Doesn't work for 1? Pity... But admirable effort... :)

yep, there are some bugs and the solution is not allways optimal. but it makes 1 L in 8 steps...

Couple golf tips - You can save 6 bytes by replacing int N,T,i; with N,T,i,a,b; and int a=0,b=0; with a=b=0;. You also get 3 bytes by adding the ( to your printf definition. I think the biggest gain would be reducing the switch statement to a nested ternary though - the case and break statements really add up.

C (480 465 bytes)
#define P printf(
#define O(x) P"%d) Pour from %dL jug into "x"\n"
#define S P"5L: %d, 3L: %d, T: %d\n",F,H,g);}
F,H,s,g,x;l(j){P"%d) Fill %dL jug\n",++s,j);St(j,o,m){O("%dL jug"),++s,j,(j^5)?5:3);Se(j,i){O("tank"),++s,j);Smain(){scanf("%d",&x);while(x>4){x-=5;l(F=5);g+=5;e(5,F=0);}while(x>2){x-=3;l(H=3);g+=3;e(3,H=0);}(x^2)?(x^1)?0:(l(H=3),t(3,H=0,F=3),l(H=3),t(3,H=1,F=5),g++,e(3,H=0)):(l(F=5),t(5,F=2,H=3),g+=2,e(5,F=0));P"Volume measured out in %d turns",s);}

Optimal version (adds 10 bytes)
#define P printf(
#define O(x) P"%d) Pour from %dL jug into "x"\n"
#define S P"5L: %d, 3L: %d, T: %d\n",F,H,g);}
F,H,s,g,x;l(j){P"%d) Fill %dL jug\n",++s,j);St(j,o,m){O("%dL jug"),++s,j,(j^5)?5:3);Se(j,i){O("tank"),++s,j);Smain(){scanf("%d",&x);while(x>4&&x^6&&x^9){x-=5;l(F=5);g+=5;e(5,F=0);}while(x>2){x-=3;l(H=3);g+=3;e(3,H=0);}(x^2)?(x^1)?0:(l(H=3),t(3,H=0,F=3),l(H=3),t(3,H=1,F=5),g++,e(3,H=0)):(l(F=5),t(5,F=2,H=3),g+=2,e(5,F=0));P"Volume measured out in %d turns",s);}

Likely more golfing to be done here - the output functions were killing me.  This should give the optimal solution (least number of steps).  Similar to other code here, it fills and empties 5L jugs until it gets below 5 and then switches to 3L jugs.  It tests for 2 special cases (6 and 9) and if it finds them switches to 3L jugs.  The instructions for getting 1L and 2L are hard coded.
More readable version:
#define P printf(
#define O(x) P"%d) Pour from %dL jug into "x"\n"
#define S P"5L: %d, 3L: %d, T: %d\n",F,H,g);}
F,H,s,g,x;
l(j)
{
    P"%d) Fill %dL jug\n",++s,j);S

t(j,o,m)
{
    O("%dL jug"),++s,j,(j^5)?5:3);S

e(j,i)
{
    O("tank"),++s,j);S

main()
{
    scanf("%d",&x);
    //while(x>4&&x^6&&x^9)     <--optimal version
    while(x>4)
    {
        x-=5;l(F=5);g+=5;e(5,F=0);
    }
    while(x>2)
    {
        x-=3;l(H=3);g+=3;e(3,H=0);
    }
    (x^2)?
        (x^1)?
            0
             :
            (l(H=3),t(3,H=0,F=3),l(H=3),t(3,H=1,F=5),g++,e(3,H=0))
             :(l(F=5),t(5,F=2,H=3),g+=2,e(5,F=0));
    P"Volume measured out in %d turns",s);
}

Edits:

Removed 10 bytes that gave the optimum performance for the scored version
based on the OP's clarification.
Shave 5 bytes by converting function to definition.

Test output for n = 11 (optimal version):
11
1) Fill 5L jug
5L: 5, 3L: 0, T: 0
2) Pour from 5L jug into tank
5L: 0, 3L: 0, T: 5
3) Fill 3L jug
5L: 0, 3L: 3, T: 5
4) Pour from 3L jug into tank
5L: 0, 3L: 0, T: 8
5) Fill 3L jug
5L: 0, 3L: 3, T: 8
6) Pour from 3L jug into tank
5L: 0, 3L: 0, T: 11
Volume measured out in 6 turns

Why don't you count 11 as a special case? What do you do for 14? One five, three threes (8) is going to beat two fives and making up the other four litres (which can't be done in four turns).

11 and 14 both include the special cases.  After you subtract the first 5L, they leave 6 and 9 respectively and these are handled by the special cases. 9 is the largest number that can be done in less steps using only a 3L jug. Input of 14 gives the 8 step solution, the output for 11 is above.

T-SQL(2012): 794 689 580
Inspired by @Jonathan-Van-Matre 's T-SQL answer in combination with @Lego-Stormtroopr's algorithm. I wanted to do this because I enjoyed the 99 Bottles of Beer challenge so much.
I tried to keep window (OVER) functions at a minimum in preference of math/bool functions.
SQLFiddle is here.
WITH n AS(SELECT 11 n UNION ALL SELECT n-IIF(n>4,5,3)FROM n WHERE n>2)SELECT n, a,LEN(a)L,i=IDENTITY(INT,1,1),'L jug'j INTO #t FROM n JOIN(VALUES(3303),(33900),(5550),(55900),(2550),(259323),(25903),(1303),(139530),(1333),(139551),(13950))x(a)ON RIGHT(LEFT(12335,n),1)=LEFT(a,1)ORDER BY n DESC SELECT LTRIM(i)+') '+REPLACE(IIF(L=4,'Fill ','Pour ')+RIGHT(a/100,L-3),9,j+' into ')+IIF(L=5,'tank',j)  +'
5L: '+LTRIM((A%100)/10)+', 3L: '+LTRIM(A%10)+', T: '+LTRIM(SUM(IIF(L=5,LEFT(a,1),0))OVER(ORDER BY i))FROM #t UNION SELECT 'Volume measured out in ' +LTRIM(MAX(i))+' turns'FROM #t

Input: 11
1) Fill 5L jug
5L: 5, 3L: 0, T: 0
2) Pour from 5L jug into tank
5L: 0, 3L: 0, T: 5
3) Fill 5L jug
5L: 5, 3L: 0, T: 5
4) Pour from 5L jug into tank
5L: 0, 3L: 0, T: 10
5) Fill 3L jug
5L: 0, 3L: 3, T: 10
6) Pour from 3L jug into
5L jug 5L: 0, 3L: 3, T: 10
7) Fill 3L jug
5L: 3, 3L: 3, T: 10
8) Pour from 3L jug into 5L jug
5L: 5, 3L: 1, T: 10
9) Pour from 3L jug into tank
5L: 5, 3L: 0, T: 11
Volume measured out in 9 turns

Human-readable:
WITH n AS(
  SELECT 11 n
    UNION ALL
  SELECT n-IIF(n>4,5,3)
  FROM n
  WHERE n>2
)
SELECT n, a,LEN(a) L, i = IDENTITY(INT,1,1), 'L jug'j
INTO #t
FROM n
JOIN(VALUES
     (3303),(33900),
     (5550),(55900),
     (2550),(259323),(25903),
     (1303),(139530),(1333),(139551),(13950)
    )x(a)
ON RIGHT(LEFT(12335,n),1) = LEFT(a,1)
ORDER BY n DESC

 SELECT LTRIM(i)+') '
  + REPLACE(IIF(L=4,'Fill ','Pour ')
  + RIGHT(a/100,L-3),9,j+' into ')+IIF(L=5,'tank',j)
  +'
5L: ' + LTRIM((A%100)/10) + ', 3L: ' + LTRIM(A%10) + ', T: '
  + LTRIM(SUM(IIF(L=5,LEFT(a,1),0))OVER(ORDER BY i)) FROM #t
UNION ALL
 SELECT 'Volume measured out in ' +LTRIM(MAX(i))+' turns'FROM #t
 DROP TABLE #t

Do you have some sample output?

@BillWoodger added output for input = 8

Thanks. 8 is quite easy. One to 11 gives the code a good stretch :-) I'm upvoting, so don't come back and tell me it doesn't work.

@Bill Thanks. Changed to input = 11

@comfortablydrei Amazing stuff using T-SQL... Taking a page from Jonathon's book...

Python 3 (417 chars)
P=print
D=divmod
N=['3L jug','5L jug','tank',0]
M=999
R=[0,0,0,M]
F=[3,5,M,M]
def o(a,b):k=a==3;P(['Pour from %s into %s','Empty %s','Fill %s'][k*2+(b==3)]%[(N[a],N[b]),(N[b])][k]);d=min(R[a],F[b]-R[b]);R[a]-=d;R[b]+=d;P('5L:',R[1],'3L:',R[0],'T:',R[2]);N[3]+=1
k,r=D(int(input()),5)
for i in'0'*k:o(3,1);o(1,2)
for x in['','c1c12','d46','c2','d434d46'][r]:o(*D(int(x,16),4))
P('Volume measured out in',N[3],'turns')

Explained
Note that we have 4 objects, namely, the 3L jug, the 5L jug, the tank, and the foutain. The only operations we can do is to move water from object a to object b. This is what function o(a, b) do in my code, it move water and print it and keep counting.
Tricks

N=['3L jug','5L jug','tank',0]. Here I need the last element to avoid IndexError. Also, it can be used as the global counting variable, without the expansive global keyword. For example, N[3] += 1
Since 0 <= a < 4, 0 <= b < 4 in function o(a, b), we can encode (a, b) into a hex digit using (a << 2) | b, and decode it using divmod(x, 4). With this trick, all 5 solutions(reminder=0, 1, 2, 3, 4), can be encoded into array ['','c1c12','d46','c2','d434d46'], which is a little bit shorter than it's original form:
A=[
    (),
    ((3,0),(0,1),(3,0),(0,1),(0,2)),
    ((3,1),(1,0),(1,2)),
    ((3,0),(0,2)),
    ((3,1),(1,0),(0,3),(1,0),(3,1),(1,0),(1,2))
]

Sample Output(n = 17)
17
Fill 5L jug
5L: 5 3L: 0 T: 0
Pour from 5L jug into tank
5L: 0 3L: 0 T: 5
Fill 5L jug
5L: 5 3L: 0 T: 5
Pour from 5L jug into tank
5L: 0 3L: 0 T: 10
Fill 5L jug
5L: 5 3L: 0 T: 10
Pour from 5L jug into tank
5L: 0 3L: 0 T: 15
Fill 5L jug
5L: 5 3L: 0 T: 15
Pour from 5L jug into 3L jug
5L: 2 3L: 3 T: 15
Pour from 5L jug into tank
5L: 0 3L: 3 T: 17
Volume measured out in 9 turns

COBOL (IBM Enterprise COBOL) 192 lines of 72 characters
This is a Proof of Concept for the Question, and the start of one for Golf-COBOL :-)
The question asks for the quickest. So, implement parallelism. Even one person can readily fill one 3L jug and one 5L jug at the same time.
Simply divide the input by eight, also leaving the remainder. Do some quick 5L/3L fills to the number of times eight fits exactly, then deal with the one through seven litres remaining.
The most interesting of the remainder is for four litres. Doing it as one litre plus three litres pushes a lot less water around, only 18 litres vs 23 for the other possibilities.
The Code (working)
   ID DIVISION
   PROGRAM-ID
   DATA DIVISION
   WORKING-STORAGE SECTION
   1.
   88 g1 VALUE ' '.
   2  PIC X
   88 H VALUE 'F'.
   88 I VALUE 'E'.
   88 J VALUE 'T'.
   2 PIC X
   88 K VALUE 'F'.
   88 L VALUE 'E'.
   88 M VALUE 'T'.
   1 R
   2 A1 PIC 999
   2 B PIC 99
   2 C PIC 9
   1 E
   2 e2 PIC X(120) VALUE "  ) Fill both jugs"
   2 e3 PIC X(120)
   88 O VALUE "5L: 0, 3L: 0, T: 000".
   2 e4 PIC X(120) VALUE "  ) Empty both jugs"
   2 e5 PIC X(120)
   2 e1 occurs 32 depending on p pic x(240)
   2 e6 pic x(99)
   1 F PIC 999 VALUE 0
   1 P PIC 99 VALUE 0
   1 P1 PIC 99
   PROCEDURE DIVISION
   ACCEPT A1
   DIVIDE A1 BY 8 GIVING B REMAINDER C
   set o to true
   move e3 to e5
   move 5 to e3(5:1)
   move 3 to e3(12:1)
   PERFORM D1 B TIMES
   EVALUATE C
   WHEN 1
   MOVE ZERO TO R
   SET K TO TRUE
   PERFORM N
   SET M TO TRUE
   PERFORM N
   SET K TO TRUE
   PERFORM N
   SET M TO TRUE
   PERFORM N
   SET L TO TRUE
   PERFORM N
   WHEN 2
   MOVE ZERO TO R
   SET H TO TRUE
   PERFORM N
   SET J TO TRUE
   PERFORM N
   SET I TO TRUE
   PERFORM N
   WHEN 3
   MOVE ZERO TO R
   SET K TO TRUE
   PERFORM N
   SET L TO TRUE
   PERFORM N
   WHEN 4
   MOVE ZERO TO R
   SET K TO TRUE
   PERFORM N
   SET M TO TRUE
   PERFORM N
   SET K TO TRUE
   PERFORM N
   SET M TO TRUE
   PERFORM N
   SET L TO TRUE
   PERFORM N
   SET K TO TRUE
   PERFORM N
   SET L TO TRUE
   PERFORM N
   WHEN 5
   MOVE ZERO TO R
   SET H TO TRUE
   PERFORM N
   SET I TO TRUE
   PERFORM N
   WHEN 6
   MOVE ZERO TO R
   SET K TO TRUE
   PERFORM N
   SET L TO TRUE
   PERFORM N
   SET K TO TRUE
   PERFORM N
   SET L TO TRUE
   PERFORM N
   WHEN 7
   MOVE ZERO TO R
   SET H TO TRUE
   PERFORM N
   SET I TO TRUE
   PERFORM N
   SET H TO TRUE
   PERFORM N
   SET J TO TRUE
   PERFORM N
   SET I TO TRUE
   PERFORM N
   END-EVALUATE
   string "Volume measured out in " delimited size P " turns"
   delimited size into e6
   if  e6(24:1) = 0
   move e6(25:) to e6 (24:)
   end-if
   move p to p1
   perform d2 p times
   DISPLAY E(481:)
   GOBACK
   D1
   ADD 1 TO P
   MOVE P TO E(1:2)
   move e2 to e1(p)
   move e3 to e1(p)(121:)
   ADD 1 TO P
   MOVE P TO E(241:2)
   ADD 8 TO F
   MOVE F TO E(378:3)
   move e4 to e1(p)
   move e5 to e1(p)(121:)
   MOVE F TO E(138:3)
   N
   ADD 1 TO P
   SET O TO TRUE
   EVALUATE TRUE
   WHEN K

   MOVE 3 TO B
   string p delimited size ") Fill 3L jug" delimited by size
   into e1(p)
   WHEN M
   COMPUTE C = C + B
   IF  C > 5
   COMPUTE B = C - 5
   MOVE 5 TO C
   ELSE
   MOVE 0 TO B
   END-IF
   string  P delimited size ") Pour from 3L jug into 5L jug"
   delimited size into e1(p)
   WHEN L
   ADD B TO F
   MOVE 0 TO B
   string  P delimited size ") Empty 3L jug into tank"
   delimited size into e1(p)
   END-EVALUATE
   EVALUATE TRUE
   WHEN H
   MOVE 5 TO C
   string  P delimited size ") Fill 5L jug"
   delimited size into e1(p)
   WHEN J
   COMPUTE B = C + B
   IF  B > 3
   COMPUTE C = B - 3
   MOVE 3 TO B
   ELSE
   MOVE 0 TO C
   END-IF
   string  P delimited size ") Pour from 5L jug into 3L jug"
   delimited size into e1(p)
   WHEN I
   ADD C TO F
   MOVE 0 TO C
   string  P delimited size ") Empty 5L jug into tank"
   delimited size into e1(p)
   END-EVALUATE
   string  "5L: " delimited size
       C delimited size ", 3L: " delimited size B(2:)
   ", T: " delimited size F delimited size
   into e1(p)(121:)
   SET g1 TO TRUE
   d2
   perform d3 2 times
   if  e1(p1)(1:1) = 0
   move e1(p1)(2:) to e1(p1)(1:120)
   end-if
   subtract 1 from p1
   d3
   if  e1(p1)(138:1) = 0
   move e1(p1)(139:) to e1(p1)(138:)
   end-if

This gets an absolute shed-load of diagnostic messages for code starting in the wrong place and shortage of required full-stops.
None of the diagnostics indicate any impact on the object code. So, despite it being a busted RC=8 I know the object will be OK, so linked it and ran it.
Here are the outputs for one to eight litres. After that, all results can be intuited. 17 and 100 are included as examples of the parallelism.
There is still much that can be done to squeeze the program down in characters, the correct output was the important thing first. Counting the characters when they are on fixed-length lines is another thing entirely.
Sample output:
1) Fill 3L jug
5L: 0, 3L: 3, T: 0
2) Pour from 3L jug into 5L jug
5L: 3, 3L: 0, T: 0
3) Fill 3L jug
5L: 3, 3L: 3, T: 0
4) Pour from 3L jug into 5L jug
5L: 5, 3L: 1, T: 0
5) Empty 3L jug into tank
5L: 5, 3L: 0, T: 1
Volume measured out in 5 turns

1) Fill 5L jug
5L: 5, 3L: 0, T: 0
2) Pour from 5L jug into 3L jug
5L: 2, 3L: 3, T: 0
3) Empty 5L jug into tank
5L: 0, 3L: 3, T: 2
Volume measured out in 3 turns

1) Fill 3L jug
5L: 0, 3L: 3, T: 0
2) Empty 3L jug into tank
5L: 0, 3L: 0, T: 3
Volume measured out in 2 turns

1) Fill 3L jug
5L: 0, 3L: 3, T: 0
2) Pour from 3L jug into 5L jug
5L: 3, 3L: 0, T: 0
3) Fill 3L jug
5L: 3, 3L: 3, T: 0
4) Pour from 3L jug into 5L jug
5L: 5, 3L: 1, T: 0
5) Empty 3L jug into tank
5L: 5, 3L: 0, T: 1
6) Fill 3L jug
5L: 5, 3L: 3, T: 1
7) Empty 3L jug into tank
5L: 5, 3L: 0, T: 4
Volume measured out in 7 turns

1) Fill 5L jug
5L: 5, 3L: 0, T: 0
2) Empty 5L jug into tank
5L: 0, 3L: 0, T: 5
Volume measured out in 2 turns

1) Fill 3L jug
5L: 0, 3L: 3, T: 0
2) Empty 3L jug into tank
5L: 0, 3L: 0, T: 3
3) Fill 3L jug
5L: 0, 3L: 3, T: 3
4) Empty 3L jug into tank
5L: 0, 3L: 0, T: 6
Volume measured out in 4 turns

1) Fill 5L jug
5L: 5, 3L: 0, T: 0
2) Empty 5L jug into tank
5L: 0, 3L: 0, T: 5
3) Fill 5L jug
5L: 5, 3L: 0, T: 5
4) Pour from 5L jug into 3L jug
5L: 2, 3L: 3, T: 5
5) Empty 5L jug into tank
5L: 0, 3L: 3, T: 7
Volume measured out in 5 turns

1) Fill both jugs
5L: 5, 3L: 3, T: 0
2) Empty both jugs
5L: 0, 3L: 0, T: 8
Volume measured out in 2 turns

1) Fill both jugs
5L: 5, 3L: 3, T: 0
2) Empty both jugs
5L: 0, 3L: 0, T: 8
3) Fill both jugs
5L: 5, 3L: 3, T: 8
4) Empty both jugs
5L: 0, 3L: 0, T: 16
5) Fill 3L jug
5L: 0, 3L: 3, T: 16
6) Pour from 3L jug into 5L jug
5L: 3, 3L: 0, T: 16
7) Fill 3L jug
5L: 3, 3L: 3, T: 16
8) Pour from 3L jug into 5L jug
5L: 5, 3L: 1, T: 16
9) Empty 3L jug into tank
5L: 5, 3L: 0, T: 17
Volume measured out in 9 turns

1) Fill both jugs
5L: 5, 3L: 3, T: 0
2) Empty both jugs
5L: 0, 3L: 0, T: 8
3) Fill both jugs
5L: 5, 3L: 3, T: 8
4) Empty both jugs
5L: 0, 3L: 0, T: 16
5) Fill both jugs
5L: 5, 3L: 3, T: 16
6) Empty both jugs
5L: 0, 3L: 0, T: 24
7) Fill both jugs
5L: 5, 3L: 3, T: 24
8) Empty both jugs
5L: 0, 3L: 0, T: 32
9) Fill both jugs
5L: 5, 3L: 3, T: 32
10) Empty both jugs
5L: 0, 3L: 0, T: 40
11) Fill both jugs
5L: 5, 3L: 3, T: 40
12) Empty both jugs
5L: 0, 3L: 0, T: 48
13) Fill both jugs
5L: 5, 3L: 3, T: 48
14) Empty both jugs
5L: 0, 3L: 0, T: 56
15) Fill both jugs
5L: 5, 3L: 3, T: 56
16) Empty both jugs
5L: 0, 3L: 0, T: 64
17) Fill both jugs
5L: 5, 3L: 3, T: 64
18) Empty both jugs
5L: 0, 3L: 0, T: 72
19) Fill both jugs
5L: 5, 3L: 3, T: 72
20) Empty both jugs
5L: 0, 3L: 0, T: 80
21) Fill both jugs
5L: 5, 3L: 3, T: 80
22) Empty both jugs
5L: 0, 3L: 0, T: 88
23) Fill both jugs
5L: 5, 3L: 3, T: 88
24) Empty both jugs
5L: 0, 3L: 0, T: 96
25) Fill 3L jug
5L: 0, 3L: 3, T: 96
26) Pour from 3L jug into 5L jug
5L: 3, 3L: 0, T: 96
27) Fill 3L jug
5L: 3, 3L: 3, T: 96
28) Pour from 3L jug into 5L jug
5L: 5, 3L: 1, T: 96
29) Empty 3L jug into tank
5L: 5, 3L: 0, T: 97
30) Fill 3L jug
5L: 5, 3L: 3, T: 97
31) Empty 3L jug into tank
5L: 5, 3L: 0, T: 100
Volume measured out in 31 turns

Admirable approach, @BillWoodger; I didn't however set a "fill both jugs" command within the available instructions... wonfderful work, and props for a) using COBOL, b) going with the quickest method route.

@WallyWest Thanks. If I think the business spec can be improved upon, I always do so :-). I didn't need the "empty into fountain" either, so two new and two not used - double failure!