text:
Generalized Gematria Calculator
Create a bidirectional Gematria calculator, for any given sequence of Unicode characters as the alphabet.
Gematri-What?
Gematria is a system of assigning numerical values to symbols, developed by ancient Greeks and adopted by ancient Jews. It is in a way like ASCII or Unicode, it's just non-linear... See the following table (full table is available in the link above):
Index     Letter   Letter name  Value
--------------------------
  0         א         "Alef"     1
  1         ב         "Bet"      2

           ...

  8         ט         "Tet"      9
  9         י         "Yud"      10
 10         כ         "Kaf"      20

           ...

 17         צ        "Tsady"     90
 18         '        "Kuf"       100
 19         ר        "Resh"      200

           ...

The names of letters are not important, only their index in the "Array" of the alphabet and the respective numerical value. The Hebrew alphabet only has 22 letters (not including "final" letters), so the maximum available value is 400.
If we borrow this system to the English alphabet (A-Z) we will end up with A=1, B=2... L=30... U=300... Z=800.
Two things we need to know.

One of the most important features in this system is calculating the "Gematria Value" of a word, by summing up its letters' values. (Some say there is a mystical connection between words, or phrases (when the value of space is zero) - that share the same Gematria Value).
Any non-negative Integer can be represented in symbols. For example (and let's stay with the English alphabet for now) the value of 32 is LB (L=30 + B=2). The value of 1024 is ZTKD (800+200+20+4. Note that ZSSKD is also 1024, but that's not a legal representation, since it can be compacted).

The Challenge
Write a program / a function / a code snippet in your language-of-choice, which is first set up with an alphabet (see API below) and then accept an argument. That argument may be an Integer, or a word/phrase. If it's an Integer - your program should output/return its representation in the alphabet symbols - the most compacted one (see (2) above). If it is a word or a phrase, your program should output/return the Gematria Value (by summing up symbols' values, not counting whitespaces, see (1) above).
API
Your program/function should accept 3 arguments. You can get them from STDIN, or as function arguments, you can even assume they are variables which initialized programmatically prior to your function invocation.

First argument - the first character (in Unicode) of the alphabet.
Second argument - the last character (in Unicode) of the alphabet.
Third argument - An Integer, to be represented in symbols, OR a
phrase which is  created by the given alphabet.

Output / Return Value: Depending on the third argument, as explained above.
Assumptions

First two arguments will always be one character long each, and the second will always be grater than the first.
The sequence (first until last, inclusive) will never include any of the values 30-39 (which represent the digits 0-9), otherwise it will make the third argument ambiguous. EDIT: It won't contain space as well, since in phrases spaces are counted as zeros.
The third argument, in case it's a phrase, may only contain spaces and letters of the given alphabet. Empty string is not a valid input (you can assume it's not empty). In case it's an Integer, you can assume it's a positive Integer.

Examples
Input                Output

A Z CODE GOLF        175
a s 512              sssssjb
A B 7                BBBA
≐ ⊐ ≤≫ ≥            1700

Scoring
Score = upvotes - length/100.0
Your code should be short, but more-importantly popular. Negative scores can also play along. The winner will be the answer with highest score in a week from now, 2014-11-29 19:20:00 UTC.

I retagged your question to the catch-all [tag:code-challenge] as I think the scoring is sufficiently different from either code golf or a standard popularity contest.

Ok. That's a lot of tags :) thanks.

What is space itself is included in the include list created by the first two characters ?

Also, what do you mean by the second assumption ? ASCII code for 0 is not 30.

@Optimizer it is in hex...

@Optimizer, you're right. I will add to assumption that space won't be there as well.

The hebrew letter names are a bit incorrect (it is "Tsadik" not "Tsady") (I am a native hebrew speaker)

I also feel like adding a column for the actual letters would be nice

@proudhaskeller this is a common mistake since you learn in kindergarten "peh tsady kuf resh" which sounds like tsadik kuf... You are welcome to confirm this with the Academy for Hebrew.

@Jacob Oh. Well, personally I don't really care about the academy. But I am still surprised. I guess it's like over here they sometimes say that native english speakers might have problems with english syntax.

@Jacob also I feel that the development of languages shouldn't be governed by some academy - natural progression is the way languages become what they are now. In the far past "Tsady" was named a bit differently, and it is how it should be.

CJam, 80 75 70 bytes, Upvotes - 0.7
Arc:Irc\-):N,f#{9,:)f*~}%N<lS-_A,s&{i{1${1$)<},)\,I+o-}h;;}{If-\f=:+}?

Test it here.
This is a full program, which takes input from STDIN and prints the result to STDOUT.
I'm not really sure how I'm supposed to shoot for popularity here, so I'm simply golfing this, hoping to get a reasonably impressive code size instead. ;)
I believe the int-to-string conversion can still be improved, but I don't see it right now.
Thanks to Optimizer for reminding me about set intersection and that empty arrays are falsy.
A                                   "Push integer 10.";
 rc:I                               "Read token, convert to character, save in I.";
     rc                             "Read token, convert to character.";
       \-)                          "Swap, subtract, increment.";
          :N                        "Store number of characters in N.";
            ,                       "Turn into range [0 1 2 ... N-1].";
             f#                     "Map 10^i onto that range.";
               {       }%           "Map this block onto the powers of 10.";
                9,                  "Create range [0 1 2 ... 8].";
                  :)                "Increment each element.";
                    f*              "Multiply each by the current power of 10.";
                      ~             "Unwrap/dump the resulting array.";
                                    "Now we've got the values of the first 9N digits.";
                         N<         "That's too much, so truncate to the first N.";
                           l        "Read the rest of the line.";
                            S-      "Remove spaces.";
                              _     "Duplicate string and get first character.";
                               A,   "Create range [0 1 2 ... 9].";
                                 s  "Turn into string '0123456789'.";
                                  & "Intersection of characters.";

{                      }{        }? "If/else depending on whether the result is empty.";
                                    "If it was a digit...";
 i                                  "Convert string to integer.";
  {                }h               "While that integer isn't zero...";
   1$                               "Copy digit values.";
     {    },                        "Filter digit values.";
      1$                            "Copy remaining integer.";
        )<                          "Increment, compare.";
                                    "This discards values greater than the integer.";
            )\                      "Slice off last digit value, and swap with list.";
              ,I+                   "Get length of list and add to I.";
                 o                  "Print character.";
                  -                 "Subtract digit value from integer.";
                     ;;             "Empty stack.";
                                    "If the string was not a number...";
                         I          "Push initial character.";
                          f-        "Subtract it from each character in string.";
                            \       "Swap differences and digit values.";
                             f=     "Use differences to index into the values.";
                               :+   "Sum up all the values.";

In the second case, the result is left on the stack, which is printed automatically at the end of the program.

Java 7, Score = Upvotes - 3.97
Yay!!! Java!!! The world's favourite golfing language in the world. What, you can actually golf in java??? Well, it's kind of like using a bulldozer to putt.
a is expected to contain the first character. b is expected to contain the last character. c is expected to have the input string.
Here is the function golfed:
int d=0;try{d=Integer.parseInt(c);}catch(Exception e){}int l=b-a+1;char[]f=new char[l];int[]g=new int[l];int h=1;int i=1;g[0]=1;f[0]=a;int j;for(j=1;j<b-a+1;){g[j]=(h+=i);f[j]=(char)(f[j++-1]+1);i*=h==10*i?10:1;}if(d==0){h=0;for(char k:c.toCharArray()){for(j=0;j<l;j++){if(f[j]==k){h+=g[j];}}}System.out.println(h);}else{c="";for(j=l;j>0;){if(g[--j]<=d){c+=f[j];d-=g[j++];}}System.out.println(c);}

Here it is indented with structure code:
public class G{

    public static void main(String[] args){
        new G(args);
    }

    public G(String[] args){
        a = args[0].charAt(0);
        b = args[1].charAt(0);
        for (int i = 2; i < args.length; i++){
            c += args[i];
        }
        function();
    }

    char a;

    char b;

    String c = "";

    void function(){
        int d=0;
        try{
            d=Integer.parseInt(c);
        }catch(Exception e){}
        int l=b-a+1;
        char[]f=new char[l];
        int[]g=new int[l];
        int h=1;
        int i=1;
        g[0]=1;
        f[0]=a;
        int j;
        for(j=1;j<b-a+1;){
            g[j]=(h+=i);
            f[j]=(char)(f[j++-1]+1);
            i*=h==10*i?10:1;
        }
        if(d==0){
            h=0;
            for(char k:c.toCharArray()){
                for(j=0;j<l;j++){
                    if(f[j]==k){
                        h+=g[j];
                    }
                }
            }
            System.out.println(h);
        }else{
            c="";
            for(j=l;j>0;){
                if(g[--j]<=d){
                    c+=f[j];
                    d-=g[j++];
                }
            }
            System.out.println(c);
        }
    }
}

Here it is completely expanded:
public class Generator{

    public static void main(String[] args){
        beginning = args[0].charAt(0);
        end = args[1].charAt(0);
        for (int i = 2; i < args.length; i++){
            phrase += args[i];
        }
        function();
    }

    static char beginning;

    static char end;

    static String phrase = "";

    static void function(){
        int convertTo = 0;
        try{
             convertTo = Integer.parseInt(phrase);
        } catch (Exception e){}
        char[] alphabet = new char[end - beginning + 1];
        int[] values = new int[alphabet.length];
        int value = 1;
        int base = 1;
        values[0] = 1;
        alphabet[0] = beginning;
        int i;
        for (i = 1; i < values.length;){
            values[i] = (value += base);
            alphabet[i] = (char)(alphabet[i++-1]+1);
            base*=value==10*base?10:1;
        }
        if(convertTo==0){
            value = 0;
            for (char character : phrase.toCharArray()){
                for (i = 0; i < alphabet.length;i++){
                    if (alphabet[i] == character){
                        value += values[i];
                    }
                }
            }
            System.out.println(value);

        } else {
            phrase = "";
            for (i = values.length;i > 0;){
                if (values[--i] <= convertTo){
                    phrase += alphabet[i];
                    convertTo -= values[i++];
                }
            }
            System.out.println(phrase);

        }
    }
}

Haskell, 188 bytes; Upvotes - 1.88
This is a full-blown STDIN-to-STDOUT program, heavily golfed. EDIT: Now in under 200 bytes! EDIT2: Saved one byte with @proudhaskeller's suggestion.
x=[1..9]++map(*10)x
f(a:_:b:_:z@(u:_))|u>'/'&&u<':'=w$read z|1<2=show.sum$map v z where v ' '=0;v c=x!!(length[a..c]-1);w 0="";w n=(\c->c:w(n-v c))$last[d|d<-[a..b],v d<=n]
main=interact$f

It constructs the infinite list of values x = [1,2,3,4,5,6,7,8,9,10,20,30,..] on the first line, and does I/O on the third line. The value of a letter c, given the range [a..b], is then the value at position length [a..c] - 1 of x. On the second line, we branch on the first letter u of the third argument, and either sum its gematria values (if u is not a digit), or greedily construct a word with the given value (if u is a digit).
Ungolfed version with more readable variable names:
values = [1..9] ++ map (*10) values
f (low:_:high:_:rest@(first:_))
  | first > '/' && first < ':' = construct $ read rest
  | otherwise                  = show . sum $ map value rest
  where value ' '   = 0
        value c     = values !! (length [low..c] - 1)
        construct 0 = ""
        construct n = (\c -> c : construct (n - value c)) $
                      last [d | d <- [low..high], value d <= n]
main = interact $ f

you could remove the {} from the where clause for a one byte gain

APL (upvotes - 1.05)
{U←⎕UCS⋄A←V↑∊(10*0,⍳⌊9÷⍨V←1+|-/U⍺)∘.×⍳9⋄⍬≢0↑⍵:+/A[1+(U⍵~' ')-U⊃⍺]⋄U(U⊃⍺)+{⍵≤0:⍬⋄(¯1+A⍳T),∇⍵-T←⊃⌽A/⍨⍵≥A}⍵}

This is a function that takes the two characters on the left, and the argument to be converted on the right:
      'A' 'Z'{U←⎕UCS⋄A←V↑∊(10*0,⍳⌊9÷⍨V←1+|-/U⍺)∘.×⍳9⋄⍬≢0↑⍵:+/A[1+(U⍵~' ')-U⊃⍺]⋄U(U⊃⍺)+{⍵≤0:⍬⋄(¯1+A⍳T),∇⍵-T←⊃⌽A/⍨⍵≥A}⍵}'CODE GOLF'
175
      gematria←{U←⎕UCS⋄A←V↑∊(10*0,⍳⌊9÷⍨V←1+|-/U⍺)∘.×⍳9⋄⍬≢0↑⍵:+/A[1+(U⍵~' ')-U⊃⍺]⋄U(U⊃⍺)+{⍵≤0:⍬⋄(¯1+A⍳T),∇⍵-T←⊃⌽A/⍨⍵≥A}⍵}
      'A' 'Z' gematria 'CODE GOLF'
175
      'a' 's' gematria 512
sssssjb
      'A' 'B' gematria 7
BBBA
      '≐' '⊐' gematria '≤≫ ≥'
1700

Ungolfed version:
gematria←{
   ⍝ get Unicode values for characters
   first last←⎕UCS¨⍺
   amount←1+last-first
   ⍝ find the value for each character in the alphabet
   alphabet←amount↑∊(10*0,⍳⌊amount÷9)∘.×⍳9

   ⍝ right arg is string: calculate number
   ⍬≢0↑⍵: +/ alphabet[1+(⎕UCS ⍵~' ')-first]

   ⍝ otherwise, right arg is number: find string
   ⎕UCS first+{
      ⍝ number ≤ 0? empty string
      ⍵≤0:⍬

      ⍝ find highest value we can subtract
      val←⊃⌽(⍵≥alphabet)/alphabet

      ⍝ return it, followed by the conversion of the rest of the number
      (¯1+alphabet⍳val), ∇⍵-val
   }⍵
}

CJam, 70 bytes, #Upvotes - 0.7
{{_9%)A@9/#*}%}:M;rcrc),\i>:QlS-_@&{Qf#M:+}{i{Q,,M{1$)<},)Q@,=@@-}h;}?

This assumes that a valid input will be passed. Takes input from STDIN like the API spec says and prints result to STDOUT.
Examples:
Input                Output

A Z CODE GOLF        175
a s 512              sssssjb
A B 7                BBBA
≐ ⊐ ≤≫ ≥            1700

Try it online here
Block wise explanation:
{{_9%)A@9/#*}%}:M;
{             }:M;              "Define a function M which takes an input array of"
                                "indeces and calculates the Gematri number for them";
 {          }%                  "Run this code block for each element of the array";
  _9%)                          "Copy the number, take modulus by 9 and increment it";
      A@                        "Put 10 on stack, and rotate to get the number on top";
        9/                      "Integer divide the number by 9";
          #                     "Calculate 10 to the power the above quotient";
           *                    "Multiply the above result by modulus 9";

rcrc),\i>:QlS-_@&
rcrc                            "Read the first two characters, representing the lower"
                                "and upper end of the character list";
    ),                          "Increment the upper end and get a list of U to ASCII 0"
                                "characters where U is the upper limit";
      \i                        "Swap and convert the lower limit to its ASCII number";
        >:Q                     "Slice the character list to get our desired character"
                                "list range and store it in Q";
           lS-                  "Read the rest of the line as string and remove spaces";
              _@&               "Take a copy, get Q on top of stack and take"
                                "intersection with the input string. If the resulting"
                                "string is empty, then the third input was a number";
                 {...}{...}?    "First code block is for string input and second for"
                                "number input based on the above intersected string";

{Qf#M:+}
 Qf#                            "For each character of input string, calculate its"
                                "position in Q";
    M                           "Get the Gematri numbers for these inceces";
     :+                         "Sum them all to get the final Gematri number for the"
                                "input string"

{i{Q,,M{1$)<},)Q@,=@@-}h;}
 i                              "Convert the input number string to integer";
  {                   }h        "Run the code block till we get 0 on top of stack";
   Q,,M                         "Get the first length(Q) Gematri numbers";
       {1$)<},                  "Filter and take only which are less than input number";
              )                 "Pop the last number from the filtered array. This is"
                                "The maximum Gematri number that can be deducted";
               Q@               "Put Q on stack and rotate the remaining filtered array"
                                "to top of stack";
                 ,              "Calculate the length of that array, which is also the"
                                "index of the Gematri number used.";
                  =             "Get the corresponding character to that Gematri number";
                   @@-          "Put the number and Gematri number on top and subtract."
                                "The next loop runs on the above result now";
                        ;       "Pop the resedual 0 from stack. The remaining stack now"
                                "contains just the Gematri characters."


text:
Magical Squares
A perfect square is a number that is the square of an integer.
However, let's define something called a Magical Square, which is a perfect square with the following restriction:
The perfect square must be the sum of the numbers 1...N for some natural number N. Write a program that calculates the first X magical squares:
The first magical square is 1 (not 0, since N >= 1). The values of X are: 1 <= X <= 15.
The program should be efficient and your score is the time taken to calculate the magical squares in seconds. The winner is the program that runs in the least amount of time. Please also include the generated numbers.
You can't hard-code the values, or read them from a file, etc. They MUST be calculated by the program.
Some examples: 1, 36, 1225, ...

How are you going to select the winner? 2. Why constant output? Wouldn't this be more interesting if the code had X as input?

So isn't this just numbers that are perfect squares AND triangular numbers?

@mdc32, yes it is.

So, essentially, if sqrt(x*(x-1)) is a whole number, then print it.

"The winner is the program that runs in the least amount of time." As measured on which machine? Unless they're all measured on the same machine (which usually means yours) this is not an objective winning criterion.

@MartinBüttner, I'll time it on my machine as well.

Are we allowed to use floating point numbers?

CJam, 1 ms
UXD{_34*2$m2+}*]1>N*

This uses the following known recurrence relation:
N[k] = 34 * N[k-1] - N[k-2] + 2

Timing/Output
$ cjam <(echo 'es:T; UXD{_34*2$m2+}*]1>N* esT-`p'); echo
"1"
1
36
1225
41616
1413721
48024900
1631432881
55420693056
1882672131025
63955431761796
2172602007770041
73804512832419600
2507180834294496361
85170343853180456676

You forgot the 15th number.

Fixed, thanks. I changed the starting values, but not the number of iterations.

Java 7, 467945 ns = .467945 ms
Using sudo's formula:
import java.math.BigInteger;
import java.io.*;

public class SquareTriangle{
    public static void main(String[] args){
        PrintStream out = new PrintStream(System.out, false);
        long startTime = System.nanoTime();
        for (int i = 0; i < 100000; i++){
            BigInteger a = 0;
            BigInteger b = 1;
            BigInteger c;
            for (int i = 0; i < 15; i++){
                out.println(b);
                c = b;
                b =  c.multiply(BigInteger.valueOf(34)).subtract(a)
                         .add(BigInteger.valueOf(2));
                a = c;
            }
        }
        long endTime = System.nanoTime();
        out.flush();
        System.out.println((endTime - startTime)/100000 + " ns");
    }
}

Takes an average of 467945 ns per run on my very slow computer.
Here are the numbers:
1
36
1225
41616
1413721
48024900
1631432881
55420693056
1882672131025
63955431761796
2172602007770041
73804512832419600
2507180834294496361
85170343853180456676
2893284510173841030625

Edit: Now flushes the output stream after it is timed, not during.

source: Stack Exchange

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

sort: votes


text:
Smallest Bytecode Interpreter/VM
Leaderboard - JIT Compiled (Lower is better)

es1024 - 81.2 points (including a working compiler!)
Kieth Randall - 116 points
Ell - 121 points

Leaderboard - Interpreted (Lower is better)

Martin Büttner - 706654 points (somewhere around 2 hours).
criptych - 30379 points (97 seconds)

Your mission, should you choose to accept it, is to write the smallest possible bytecode interpreter/VM. The VM/interpreter uses a small CISC architecture (operations can vary in size), with the language specified below. Upon completion, you must print the value of the 3 CPU registers to prove that the correct output is printed (3,126,900,366).
Compiler
If you'd like to make your own tests, a compiler is posted below. Feel free to post your tests with your answer.

window.compile=function(){var e=$("#text").val().toLowerCase().match(/[^\r\n]+/g);var t=[];for(var n=0;n<e.length;n++)compileLine(e[n],t);var r="";for(var n=0;n<t.length;n++)if(typeof t[n]=="string")r+="\n";else r+="0x"+t[n].toString(16)+" ";$("#compiledArray").val(r)};window.compileLine=function(e,t){var n=e.split(" ");if(n[0]=="load"){t.push(0);t.push(getInt(n[1]));t.pushArr(getInt(n[2]))}if(n[0]=="rload"){t.push(1);t.push(getInt(n[1]));t.push(getInt(n[1]))}if(n[0]=="push"){t.push(2);t.push(getInt(n[1]))}if(n[0]=="pop"){t.push(3);t.push(getInt(n[1]))}if(n[0]=="add"){t.push(4);t.push(getInt(n[1]));t.push(getInt(n[2]))}if(n[0]=="sub"){t.push(5);t.push(getInt(n[1]));t.push(getInt(n[2]))}if(n[0]=="mul"){t.push(6);t.push(getInt(n[1]));t.push(getInt(n[2]))}if(n[0]=="div"){t.push(7);t.push(getInt(n[1]));t.push(getInt(n[2]))}if(n[0]=="jmp"){t.push(8);t.pushArr(getInt(n[1]))}if(n[0]=="cmp"){t.push(9);t.push(getInt(n[1]));t.push(getInt(n[2]))}if(n[0]=="branchlt"){t.push(10);t.pushArr(getInt(n[1]))}if(n[0]=="brancheq"){t.push(11);t.pushArr(getInt(n[1]))}if(n[0]=="branchgt"){t.push(12);t.pushArr(getInt(n[1]))}if(n[0]=="branchne"){t.push(13);t.pushArr(getInt(n[1]))}t.push("NEW LINE")};window.getInt=function(e){if(e.trim().startsWith("<--"))return"COMMENT";if(e=="r0")return 0;if(e=="r1")return 1;if(e=="r2")return 2;if(e.startsWith("0x"))return parseInt(e,16);if(isNaN(parseInt(e)))alert(e);return getIntBytes(parseInt(e))};if(typeof String.prototype.startsWith!="function"){String.prototype.startsWith=function(e){return this.slice(0,e.length)==e}}Array.prototype.pushArr=function(e){this.push.apply(this,e)};window.getIntBytes=function(e){var t=[];var n=4;do{t[--n]=e&255;e=e>>8}while(n);return t}

<textarea id="text" cols="40" rows="10"></textarea>

<button onclick="compile()">Compile</button>

<textarea id="compiledArray"  cols="40" rows="10" readonly></textarea>

"VM" Specifications
The VM has 3 32 bit unsigned integral registers: R0, R1, R2. They are represented in hex as 0x00, 0x01, and 0x02.
The following operations must be supported:
The format is [name] [...operands...], [hexadecimal op-code] [...operands repeated...]

LOAD [register] [4 byte value], 0x00 [register] [4 byte value]
PUSH [register], 0x02 [register]
POP [register], 0x03 [register]
ADD [register, 1 byte] [register, 1 byte], 0x04 [register] [register]
SUB [register, 1 byte] [register, 1 byte], 0x05 [register] [register]
MUL [register, 1 byte] [register, 1 byte], 0x06 [register] [register]
DIV [register, 1 byte] [register, 1 byte], 0x07 [register] [register]
JMP [code line, 4 bytes], 0x08 [4 byte code line number]
CMP [register, 1 byte] [register, 1 byte], 0x09 [register] [register]
BRANCHLT [code line, 4 bytes], 0x0a [4 byte code line number]

Some notes:

The above math operations add the values of 2 registers together, placing the output in the first register.
CMP, the comparison operator, should compare the values of 2 registers and store the output in some internal flag (this can be implementation specific) for future use on branch instructions.
If BRANCH is called before CMP, unless BRANCHEQ is called, the "VM" should not branch.
PUSH/POP unsurprisingly push or pop numbers from the stack.
Jump and Branch operators jump to a specific operation (line of code), not a binary address.
Branch operations do not do the comparison. Rather, they take the output from the last comparison to execute.
Branch and Jump operators use a zero based line number indexing system. (E.g. JMP 0 jumps to the first line)
All operations are to be performed on unsigned numbers which overflow to zero and do not throw an exception on an integer overflow.
Division by zero is not allowed and as such, the behavior of the program is not defined. You can (for example)...

Crash the program.
End execution of the VM and return it's current state.
Show a "ERR: Division by 0" message.

Termination of the program is defined as when the instruction pointer reaches the end of the program (a non empty program can be assumed).

Output
The output must be exactly this (newlines included)
R0 3126900366
R1 0
R2 10000

Points
Points are calculated based on the following formula: Number Of Characters * (Seconds Needed To Run / 2)
To avoid hardware differences causing different times, each test will be run on my computer (i5-4210u, 8GB ram) in either ubuntu server or Windows 8, so try not to use some insane-exotic-runtime that only compiles on a Dual G5 Mac Pro with exactly 762.66 mb of free RAM.
If you are using a specialized runtime/language, please post a link to it.

For interested parties, I have posted the testing code (written in C#) here: http://pastebin.com/WYCG5Uqu

Test Program
The idea came from here, so we'll use a somewhat modified version of their program.
The correct output for the program is: 3,126,900,366
In C:
int s, i, j;
for (s = 0, i = 0; i < 10000; i++) {
    for (j = 0; j < 10000; j++)
        s += (i * j) / 3;
}

In code:
[R0 is representative of s, R1 of j, R2 of i]
LOAD R0 0
LOAD R2 0 <--outer loop value
LOAD R1 0 <--inner loop value
     --Begin inner loop--
PUSH R1 <--push inner loop value to the stack
MUL R1 R2 <--(i*j)
PUSH R2
LOAD R2 3
DIV R1 R2 <-- / 3
POP R2
ADD R0 R1 <-- s+=
POP R1
PUSH R2
LOAD R2 1
ADD R1 R2 <--j++
POP R2
PUSH R2
LOAD R2 10000
CMP R1 R2 <-- j < 10000
POP R2
BRANCHLT 3 <--Go back to beginning inner loop
--Drop To outer loop--
LOAD R1 1
ADD R2 R1 <--i++
LOAD R1 10000
CMP R2 R1 <-- i < 10000
LOAD R1 0 <--Reset inner loop
BRANCHLT 2

In binary/hex:
0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x02 0x00 0x00 0x00 0x00
0x00 0x01 0x00 0x00 0x00 0x00
0x02 0x01
0x06 0x01 0x02
0x02 0x02
0x00 0x02 0x00 0x00 0x00 0x03
0x07 0x01 0x02
0x03 0x02
0x04 0x00 0x01
0x03 0x01
0x02 0x02
0x00 0x02 0x00 0x00 0x00 0x01
0x04 0x01 0x02
0x03 0x02
0x02 0x02
0x00 0x02 0x00 0x00 0x27 0x10
0x09 0x01 0x02
0x03 0x02
0x0a 0x00 0x00 0x00 0x03
0x00 0x01 0x00 0x00 0x00 0x01
0x04 0x02 0x01
0x00 0x01 0x00 0x00 0x27 0x10
0x09 0x02 0x01
0x00 0x01 0x00 0x00 0x00 0x00
0x0a 0x00 0x00 0x00 0x02

Bonus Points
 (Effects are applied multiplicatively) E.g. if you qualify for all three, it would be ((characters * 0.50) * 0.75) * 0.90

50% decrease if the interpreter is actually a JIT compiler
25% decrease if it applies any sort of loop unrolling/meaningful optimization.
10% decrease if you extend the VM with

BRANCHEQ [code line, 4 bytes] (Branch if equal - opcode 0x0b)
BRANCHGT [code line, 4 bytes] (Branch if greater than - opcode 0x0c)
BRANCHNE [code line, 4 bytes] (Branch if not equal - opcode 0x0d)
RLOAD [register 1] [register 2] (move the value of register 2 to register 1 - opcode 0x01).

Disallowed

Precompiling the test case into the program is prohibited. You must either accept the bytecode from STDIN or from a file (Doesn't matter which).
Returning the output without running the program.
Any other way you can think of to cheat the VM requirement.

Why not include a few more test programs to discourage the things you said are disallowed? If it's a VM, it should be able to run anything written in the bytecode specification, right?

I will try to do that tonight. I am writing the compiler right now.

The compiler is here http://jsfiddle.net/aL9y19bd/23/

Does CMP check for less than or equality? And what happens to its result?

MUL and DIV are also underspecified. Should they be signed or unsigned? What happens on multiplication overflow?

As for the BRANCH** opcodes, what is compared (value from a register, value from stack, something else)?

Actually that's called multiplicative stacking for the bonuses, not linear (or additive)

@Claudiu There - fixed. Thanks for pointing that out; I thought linear wasn't the right word.

@es1024 CMP compares the value of 2 registers and stores the result internally so it can do BRANCH** operations.
BRANCH** opcodes do not actually do a comparison. They use the result of the previous CMP operation to decide whether to jump or not. - I somewhat modeled this after x86 assembly.

@feersum Math is unsigned and on an integer overflow, overflow to zero rather than crashing.

A few notes: (a) The second and third lines in the binary test program are swapped. (b) The final value of R0 is 3126900366 (which is -1168066930 as a signed value.)

@Ell I just spent an hour or two on finding (a). Now my short but slow solution will look really bad next to yours. :D There's also 3 redundant operations in the bytecode. There's POP R2 PUSH R2 and the LOAD R1 0 at the end.

What would be considered as a meaningful optimization?

@es1024 Sorry. That was also a bit vague. A "meaningful optimization" is defined as any change from the code provided to the code executed that measurably improves performance. For example, detecting that 2 of the operations, in a row, are "POP R2" and "PUSH R2" and removing them because they do not change the behavior of the program would be an optimization. So, optimization could be dead code detection, loop unrolling, etc.

@Ell - Thanks, I hadn't realized. I have updated the post to reflect this.

@MartinBüttner That was on purpose. Have to provide some room for optimization...and your answer is still awesome. I don't think I could write a hello world program in less than 250 characters, much less an entire VM.

What about full line comments (e.g. "     -- Foo bar baz -- ")? Are they counted into the line number branch logic or do line numbers relate to lines after stripping the source of those full line comments?

C, 752 (589+163 for define flags) * 0.5 (JIT) * 0.9 (extensions) * (0.75 optimization) * (0.64 seconds/2) = 81.216
C[S],J[S],i,j,k,y,c,X,Y,Z;char*R,a,b[9];main(x){R=mmap(0,S,6,34,-1,0);N=85;while(scanf("%c%s%*[ R]%d%*[ R]%d",&a,b,&x,&y)&&~getchar())a-=65,a-1?a-15?a-9?a?a-2?a-3?a-11?a-12?a-17?(N=41,v):(N=137,v):(N=137,u,N=247,g(H,4),N=139,u):(y?N=189+x,s(y):(N=51,g(G,G))):(N=137,u,N=247,g(H,6),N=139,u):(N=57,v,s(0xFC8A9F),--j):(N=1,v):(N=233,J[k++]=i,s(x)):b[1]-80?N=85+x:(N=93+x):(c=b[5],s(0x0F9EE78A),N=(c-69?c-71?c-76?1:8:11:0)+132,J[k++]=i,s(x)),C[++i]=j;U(E8,X)U(F0,Y)U(F8,Z)s(50013);i=j;while(k--)j=C[J[k]]+1,R[j-1]-233&&(j+=4),s(C[*(int*)(R+j)]-j-4);((int(*)())R)();printf("%u %u %u\n",X,Y,Z);}

Takes code (LOAD R0, etc), no trailing characters, single space, no blank lines in the middle, no comments, etc. Trailing newline required.
This is then converted to 80386 bytecode and executed.
Loading 0 into a register is replaced by xoring the register with itself instead of moving 0 into the register, which is three bytes shorter in the generated bytecode, and may be very marginally faster.
Compile with:
gcc -m32 -D"g(a,b)=(N=192|b<<3|a)"-D"s(b)=(*(int*)(R+j)=b,j+=4)"-DN=R[j++]-D"G=((x+1)|4)"
-D"H=((y+1)|4)"-DS=9999-D"u=g(0,G)"-D"v=g(G,H)"-D"U(b,c)=s(0xA3##b##89),--j,s(&c);"
bytecode.c -o bytecode

POSIX-compliant OS required.
Input is read from STDIN (use ./bytecode < file to pipe from a file).
Resulting bytecode for the test program:

; start
 0:   55                      push   %ebp
; LOAD R0 0
 1:   33 ed                   xor    %ebp,%ebp
; LOAD R2 0
 3:   33 ff                   xor    %edi,%edi
; LOAD R1 0
 5:   33 f6                   xor    %esi,%esi
; PUSH $1
 7:   56                      push   %esi
; MUL R1 R2
 8:   89 f0                   mov    %esi,%eax
 a:   f7 e7                   mul    %edi
 c:   8b f0                   mov    %eax,%esi
; PUSH R2
 e:   57                      push   %edi
; LOAD R2 3
 f:   bf 03 00 00 00          mov    $0x3,%edi
; DIV R1 R2
14:   89 f0                   mov    %esi,%eax
16:   f7 f7                   div    %edi
18:   8b f0                   mov    %eax,%esi
; POP R2
1a:   5f                      pop    %edi
; ADD R0 R1
1b:   01 f5                   add    %esi,%ebp
; POP R1
1d:   5e                      pop    %esi
; PUSH R2
1e:   57                      push   %edi
; LOAD R2 1
1f:   bf 01 00 00 00          mov    $0x1,%edi
; ADD R1 R2
24:   01 fe                   add    %edi,%esi
; POP R2
26:   5f                      pop    %edi
; PUSH R2
27:   57                      push   %edi
; LOAD R2 10000
28:   bf 10 27 00 00          mov    $0x2710,%ed
; CMP R1 R2
2d:   39 fe                   cmp    %edi,%esi
2f:   9f                      lahf
30:   8a fc                   mov    %ah,%bh
; POP R2
32:   5f                      pop    %edi
; BRANCHLT 3
33:   8a e7                   mov    %bh,%ah
35:   9e                      sahf
36:   0f 8c cb ff ff ff       jl     0x7
; LOAD R1 1
3c:   be 01 00 00 00          mov    $0x1,%esi
; ADD R2 R1
41:   01 f7                   add    %esi,%edi
; LOAD R1 10000
43:   be 10 27 00 00          mov    $0x2710,%es
; CMP R2 R1
48:   39 f7                   cmp    %esi,%edi
4a:   9f                      lahf
4b:   8a fc                   mov    %ah,%bh
; LOAD R1 0
4d:   33 f6                   xor    %esi,%esi
; BRANCHLT 2
4f:   8a e7                   mov    %bh,%ah
51:   9e                      sahf
52:   0f 8c ad ff ff ff       jl     0x5
; copy R0 to X
58:   89 e8                   mov    %ebp,%eax
5a:   a3 28 5b 42 00          mov    %eax,0x425b
; copy R1 to Y
5f:   89 f0                   mov    %esi,%eax
61:   a3 38 55 44 00          mov    %eax,0x4455
; copy R2 to Z
66:   89 f8                   mov    %edi,%eax
68:   a3 40 55 44 00          mov    %eax,0x4455
; exit
6d:   5d                      pop    %ebp
6e:   c3                      ret

Ungolfed:

C[9999],J[9999],i,j,k,y,c,X,Y,Z;
char *R,a,b[9];
main(x){
    // 6 is PROC_WRITE|PROC_EXEC
    // 34 is MAP_ANON|MAP_PRIVATE
    R=mmap(0,'~~',6,34,-1,0);

    N=0x55;
    while(scanf("%c%s%*[ R]%d%*[ R]%d",&a,b,&x,&y)&&~getchar())
        a-=65,
        a-1? // B[RANCH**]
            a-15? // P[USH/OP]
                a-9? // J[MP]
                    a? // A[DD]
                        a-2? // C[MP]
                            a-3? // D[IV]
                                a-11? // L[OAD]
                                    a-12? // M[UL]
                                        a-17? // R[LOAD]
                                            // SUB
                                            (N=0x29,g(G,H))
                                        :(N=0x89,g(G,H))
                                    :(N=0x89,g(0,G),N=0xF7,g(H,4),N=0x8B,g(0,G))
                                :(y?N=0xBD+x,s(y):(N=0x33,g(G,G)))
                            :(N=0x89,g(0,G),N=0xF7,g(H,6),N=0x8B,g(0,G))
                        :(N=0x39,g(G,H),s(0xfc8a9f),--j)
                    :(N=0x1,g(G,H))
                :(N=0xE9,J[k++]=i,s(x))
            :b[1]-80?
                N=0x55+x // PUSH
            :(N=0x5D+x) // POP
        :(c=b[5],s(0x0f9ee78a),N=(
        c-69? // EQ
            c-71? // GT
                c-76? // LT
                    1 // NE
                :8
            :11
        :0
        )+0x84,J[k++]=i,s(x)),
        C[++i]=j
        ;
    // transfer registers to X,Y,Z
    s(0xA3E889),--j,s(&X);
    s(0xA3F089),--j,s(&Y);
    s(0xA3F889),--j,s(&Z);

    // pop and ret
    s(0xC35D);

    i=j;
    // fix distances for jmp/branch**
    while(k--)
        j=C[J[k]]+1,R[j-1]-0xE9&&(j+=4),
        s(C[*(int*)(R+j)]-j-4);

    // call
    ((int(*)())R)();

    // output
    printf("%u %u %u\n",X,Y,Z);
}

Wow. I wish I would have added a bonus for including the compiler in the VM.

Average of .67 seconds per run over 15 runs.

I have to disagree that the xoring is an optimization. While clever code size wise, xoring does not change the performance characteristics of VM (correct me if I'm wrong). What I meant by optimization was changing or removing instructions from the input code (e.g. removing the redundant POP...PUSH) or realizing 2 instructions in a row load the register, so one can be removed, etc.

EDIT: Actually, that is an optimization: it dropped to 0.64 seconds per run over 15 runs. I guess it prevents cache thrashing or something by shortening the code (or removes redundant memory accesses)?

@ColorfullyMonochrome Some architectures, when presented with the xoring of a register to itself, will not actually execute the instruction, but simply zero the register itself.

Oh, that makes sense. And, as the load 0's are being called very often, it provides a meaningful difference.

It's actually 4 times faster: http://stackoverflow.com/a/18027854/995714. It doesn't actually execute an opcode at all, it seems.

C, Score = 854byte × (~0.8sec / 2) × 0.5 [JIT] × 0.9 [Extensions] = ~154byte sec
#define G getchar()
#define L for(i=0;i<3;++i)
#define N*(int*)
#define M(x)"P\x8a\xe7\x9e\xf"#x"    KL"
*T[1<<20],**t=T,*F[1<<20],**f=F,R[3],r[]={1,6,7};char*I[]={"L\xb8    GGJH","I\x8b\xc0HHGH","H\x50GG","H\x58GG","I\3\xc0HHGH","I\53\xc0HHGH","M\x8b\xc0\xf7\xe0\x8b\xc0IHLGJ","O\63\xd2\x8b\xc0\xf7\xf0\x8b\xc0IJNGL","L\xe9    KH","L\73\xc0\x9f\x8a\xfcHHGH",M(\x82),M(\x84),M(\x87),M(\x85)},C[1<<24],*c=C;main(i,o,l,g){N c=0xb7ec8b60;c[4]=70;c+=5;while((o=G)>=0){char*s=I[o];l=*s-'G';memcpy(c,s+1,l);for(s+=l+1;o=*s++;){o-='G';if(o<3){g=r[G];c[*s++-'G']|=g<<3*(o&1);if(o>1)c[*s++-'G']|=g<<3;}else{if(o>3)*f++=c+*s-'G';for(i=4;i;--i)c[*s-'G'+i-1]=G;++s;}}*t++=c;c+=l;}*t=c;while(f>F)--f,**f=(int)T[**f]-(int)*f-4;L N&c[7*i]=0x5893e|r[i]<<19,N&c[3+7*i]=R+i;N&c[21]=0xc361e58b;mprotect((int)C>>12<<12,1<<24,7);((void(*)())C)();L printf("R%d %u\n",i,R[i]);}

Compile with gcc vm.c -ovm -m32 -w on a x86 POSIX compliant OS.
Run with ./vm < program, where program is a binary program file.

Going for the speed.
The program performs a pretty straight-forward translation of the input program to x86 machine code and lets the CPU do the rest.
For instance, here's the translation of the test program.
ecx, esi and edi correspond to R0, R1 and R2, respectively; bh holds the status flags; eax and edx are scratch registers; the call-stack corresponds to the VM's stack:
# Prologue
     0:   60                      pusha
     1:   8b ec                   mov    ebp,esp
     3:   b7 46                   mov    bh,0x46
# LOAD R0 0
     5:   b9 00 00 00 00          mov    ecx,0x0
# LOAD R2 0 <--outer loop value
     a:   bf 00 00 00 00          mov    edi,0x0
# LOAD R1 0 <--inner loop value
     f:   be 00 00 00 00          mov    esi,0x0
#      --Begin inner loop--
# PUSH R1 <--push inner loop value to the stack
    14:   56                      push   esi
# MUL R1 R2 <--(i*j)
    15:   8b c6                   mov    eax,esi
    15:   f7 e7                   mul    edi
    19:   8b f0                   mov    esi,eax
# PUSH R2
    1b:   57                      push   edi
# LOAD R2 3
    1c:   bf 03 00 00 00          mov    edi,0x3
# DIV R1 R2 <-- / 3
    21:   33 d2                   xor    edx,edx
    23:   8b c6                   mov    eax,esi
    25:   f7 f7                   div    edi
    27:   8b f0                   mov    esi,eax
# POP R2
    29:   5f                      pop    edi
# ADD R0 R1 <-- s+=
    2a:   03 ce                   add    ecx,esi
# POP R1
    2c:   5e                      pop    esi
# PUSH R2
    2d:   57                      push   edi
# LOAD R2 1
    2e:   bf 01 00 00 00          mov    edi,0x1
# ADD R1 R2 <--j++
    33:   03 f7                   add    esi,edi
# POP R2
    35:   5f                      pop    edi
# PUSH R2
    36:   57                      push   edi
# LOAD R2 10000
    37:   bf 10 27 00 00          mov    edi,0x2710
# CMP R1 R2 <-- j < 10000
    3c:   3b f7                   cmp    esi,edi
    3e:   9f                      lahf
    3f:   8a fc                   mov    bh,ah
# POP R2
    41:   5f                      pop    edi
# BRANCHLT 4 <--Go back to beginning inner loop
    42:   8a e7                   mov    ah,bh
    44:   9e                      sahf
    45:   0f 82 c9 ff ff ff       jb     0x14
# --Drop To outer loop--
# LOAD R1 1
    4b:   be 01 00 00 00          mov    esi,0x1
# ADD R2 R1 <--i++
    50:   03 fe                   add    edi,esi
# LOAD R1 10000
    52:   be 10 27 00 00          mov    esi,0x2710
# CMP R2 R1 <-- i < 10000
    57:   3b fe                   cmp    edi,esi
    59:   9f                      lahf
    5a:   8a fc                   mov    bh,ah
# LOAD R1 0 <--Reset inner loop
    5c:   be 00 00 00 00          mov    esi,0x0
# BRANCHLT 3
    61:   8a e7                   mov    ah,bh
    63:   9e                      sahf
    64:   0f 82 a5 ff ff ff       jb     0xf
# Epilogue
    6a:   3e 89 0d 60 ac 04 09    mov    DWORD PTR ds:0x904ac60,ecx
    71:   3e 89 35 64 ac 04 09    mov    DWORD PTR ds:0x904ac64,esi
    78:   3e 89 3d 68 ac 04 09    mov    DWORD PTR ds:0x904ac68,edi
    7f:   8b e5                   mov    esp,ebp
    81:   61                      popa
    82:   c3                      ret

Ungolfed

#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <sys/mman.h>

#define MAX_INST_COUNT (1 << 20)
#define MAX_CODE_SIZE (8 * MAX_INST_COUNT)
#define PAGE_SIZE (1 << 12)

uintptr_t *targets[MAX_INST_COUNT], **targets_ptr = targets;
int32_t *fixups[MAX_INST_COUNT], **fixups_ptr = fixups;
char code[MAX_CODE_SIZE], *code_ptr = code;
uint32_t R[3];

const char* inst_defs[] = {
    /* LOAD     */ "\5\xb8    \1\0\4\1",
    /* RLOAD    */ "\2\x8b\xc0\2\1\1\1",
    /* PUSH     */ "\1\x50\1\0",
    /* POP      */ "\1\x58\1\0",
    /* ADD      */ "\2\x03\xc0\2\1\1\1",
    /* SUB      */ "\2\x2b\xc0\2\1\1\1",
    /* MUL      */ "\6\x8b\xc0\xf7\xe0\x8b\xc0\3\1\5\1\3",
    /* DIV      */ "\x8\x33\xd2\x8b\xc0\xf7\xf0\x8b\xc0\3\3\7\1\5",
    /* JMP      */ "\5\xe9    \5\1",
    /* CMP      */ "\5\x3b\xc0\x9f\x8a\xfc\2\1\1\1",
    /* BRANCHLT */ "\x9\x8a\xe7\x9e\x0f\x82    \5\5",
    /* BRANCHEQ */ "\x9\x8a\xe7\x9e\x0f\x84    \5\5",
    /* BRANCHGT */ "\x9\x8a\xe7\x9e\x0f\x87    \5\5",
    /* BRANCHNE */ "\x9\x8a\xe7\x9e\x0f\x85    \5\5"
};

int main() {
    int i;

    {
        const char prologue[] =
            /* PUSHAD       */ "\x60"
            /* MOV EBP, ESP */ "\x8b\xec"
            /* MOV BH, 46h  */ "\xb7\x46"
        ;
        memcpy(code_ptr, prologue, sizeof(prologue) - 1);
        code_ptr += sizeof(prologue) - 1;
    }

    {
        const char reg[] = {1, 6, 7};
        char r;
        int op;
        while ((op = getchar()) != EOF) {
            const char* def = inst_defs[op];
            int len = def[0];
            memcpy(code_ptr, def + 1, len);
            for (def += len + 1; *def; ) {
                switch (*def++) {
                    case 1: code_ptr[*def++] |= reg[getchar()]; break;
                    case 2: code_ptr[*def++] |= reg[getchar()] << 3; break;
                    case 3:
                        r = reg[getchar()];
                        code_ptr[*def++] |= r; code_ptr[*def++] |= r << 3;
                        break;
                    case 5: *fixups_ptr = code_ptr + *def; ++fixups_ptr;
                    case 4:
                        for (i = 4; i; --i) code_ptr[*def + i - 1] = getchar();
                        ++def;
                        break;
                }
            }
            *targets_ptr = code_ptr; ++targets_ptr;
            code_ptr += len;
        }
        *targets_ptr = code_ptr; ++targets_ptr;

        while (fixups_ptr != fixups) {
            --fixups_ptr;
            **fixups_ptr = (char*)targets[**fixups_ptr] - (char*)*fixups_ptr - 4;
        }
    }

    {
        const char epilogue[] =
            /* MOV R[0], ECX */ "\x3e\x89\x0d    "
            /* MOV R[1], ESI */ "\x3e\x89\x35    "
            /* MOV R[2], EDI */ "\x3e\x89\x3d    "
            /* MOV ESP, EBP  */ "\x8b\xe5"
            /* POPAD         */ "\x61"
            /* RET           */ "\xc3"
        ;
        memcpy(code_ptr, epilogue, sizeof(epilogue) - 1);
        for (i = 0; i < 3; ++i) *(uintptr_t*)&code_ptr[3 + 7 * i] = &R[i];
        code_ptr += sizeof(epilogue) - 1;
    }

    mprotect(
        (uintptr_t)code / PAGE_SIZE * PAGE_SIZE, MAX_CODE_SIZE,
        PROT_READ | PROT_WRITE | PROT_EXEC
    );
    { void (*program)(void) = code; program(); }
    for (i = 0; i < 3; ++i) printf("R%d %u\n", i, R[i]);

    return 0;
}

Wow...my JIT was ~900 lines of code (written in c++)...

Average of 0.63 seconds per run for 15 runs.

CJam, 222 187 185 bytes * (too slow / 2)
I just wanted to see how short I can get a bytecode VM by writing it in CJam. Less than 200 bytes seems pretty decent. It's damn slow though, because CJam itself is interpreted. It takes ages to run the test program.
304402480 6b:P;q:iD-);{(_P=@/(\L*@@+\}h;]:P;TTT]:R;{_Rf=~}:Q;{4G#%R@0=@t:R;}:O;{TP=("R\(\GG*bt:R;  ~R= R\~@t:R; Q+O Q4G#+-O Q*O Q/O ~(:T; Rf=~-:U; GG*bU0<{(:T}*;"S/=~T):TP,<}g3,{'R\_S\R=N}/

To run it, download the Java interpreter at this sourceforge link, save the code in vm.cjam and run it with
java -jar cjam-0.6.2.jar vm.cjam

The program expects the bytecode on STDIN. I haven't found a way yet to pipe binary data into a program, without PowerShell adding a trailing line break and converting 0x0a to 0x0d 0x0a, which is really annoying. The code includes 4 bytes to fix that (D-);), which I haven't included in the total count, because it's not something the program should need to do if it actually received the bytecode itself on STDIN, instead of some weirdly encoded version of it. If someone knows a fix for that, please let me know.
Slightly ungolfed:
304402480 6b:P; "Create lookup table for instruction sizes. Store in P.";
q:i             "Read program and convert bytes to integers.";
D-);            "Remove spurious carriage returns. This shouldn't be necessary.";
{(_P=@/(\L*@@+\}h;]:P; "Split into instructions. Store in P.";
"We'll use T for the instruction pointer as it's initialised to 0.";
"Likewise, we'll use U for the CMP flag.";
TTT]:R; "Store [0 0 0] in R for the registers.";
{_Rf=~}:Q; "Register lookup block.";
{4G#%R@0=@t:R;}:O; "Save in register block.";
{TP=("R\(\GG*bt:R;

~R=
R\~@t:R;
Q+O
Q4G#+-O
Q*O
Q/O
~(:T;
Rf=~-:U;
GG*bU0<{(:T}*;"N/=~T):TP,<}g "Run program.";
3,{'R\_S\R=N}/

I'll add a proper explanation tomorrow.
In short, I'm storing all the registers, the instruction pointer and the comparison flag in variables, so that I can keep CJam's stack free to use as the VM's stack.

Let us continue this discussion in chat.

15.279 seconds average for 20 iterations. - 15 tests. That means 2.12208333 hours per test.

python/c++, score=56.66
1435 chars * .234/2 seconds * .5 [JIT] * .75 [Optimization] * .90 [Extra instructions]
Compiles the input program to c++, runs gcc on it, then runs the result.  Most of the time is spent inside gcc.
The one optimization I do is reduce the stack operations to explicit variables if it is allowed semantically.  It helps a lot, about 10x better runtime of the compiled code (about .056 sec to actually run the resulting binary).  I'm not sure what gcc is doing that gets you that improvement, but it's good.
import sys,os
x=map(ord,sys.stdin.read())
w=lambda x:(x[0]<<24)+(x[1]<<16)+(x[2]<<8)+x[3]
I=[]
while x:
 if x[0]==0:f='r%d=%d'%(x[1],w(x[2:]));n=6
 if x[0]==1:f='r%d=r%d'%(x[1],x[2]);n=3
 if x[0]==2:f='P%d'%x[1];n=2
 if x[0]==3:f='O%d'%x[1];n=2
 if x[0]==4:f='r%d=r%d+r%d'%(x[1],x[1],x[2]);n=3
 if x[0]==5:f='r%d=r%d-r%d'%(x[1],x[1],x[2]);n=3
 if x[0]==6:f='r%d=r%d*r%d'%(x[1],x[1],x[2]);n=3
 if x[0]==7:f='r%d=r%d/r%d'%(x[1],x[1],x[2]);n=3
 if x[0]==8:f='goto L%d'%w(x[1:]);n=5
 if x[0]==9:f='a=r%d;b=r%d'%(x[1],x[2]);n=3
 if x[0]==10:f='if(ab)goto L%d'%w(x[1:]);n=5
 if x[0]==13:f='if(a!=b)goto L%d'%w(x[1:]);n=5
 I+=[f];x=x[n:]
D=[]
d=0
for f in I:D+=[d];d+='P'==f[0];d-='O'==f[0]
J=[]
if all(d==D[int(f[f.find('L')+1:])]for f,d in zip(I,D)if f[0]in'gi'):
 H='uint32_t '+','.join('s%d'%i for i in range(max(D)))+';'
 for f,d in zip(I,D):
  if f[0]=='P':f='s%d=r'%d+f[1:]
  if f[0]=='O':f='r'+f[1:]+'=s%d'%(d-1)
  J+=[f]
else:
 H='std::vector<uint32_t>s;'
 for f,d in zip(I,D):
  if f[0]=='P':f='s.push_back(r'+f[1:]+')'
  if f[0]=='O':f='r'+f[1:]+'=s.back();s.pop_back()'
  J+=[f]
P='#include<vector>\n#include<cstdint>\nuint32_t r0,r1,r2,a,b;'+H+'int main(){'
for i,f in enumerate(J):P+='L%d:'%i+f+';'
P+=r'printf("R0 %u\nR1 %u\nR2 %u\n",r0,r1,r2);}'
c=open("t.cc", "w")
c.write(P)
c.close()
os.system("g++ -O1 t.cc")
os.system("./a.out")

Could certainly be golfed some more.

Average of .477 seconds per run over 15 runs.

Lua 5.2 (or LuaJIT), 740 bytes
First try, only minimally golfed. This version works (at least on the test program), and implements the extra opcodes, but doesn't uphold the unsigned math requirement and isn't particularly fast. As a bonus, though, it's a VM running in a VM, and is written such that it can be either interpreted (run with PUC-Lua) or sort-of-JIT (run with LuaJIT; still interpreted, but the interpreter is now JITted).
EDIT: Golfed better, still big.
EDIT: Fixed a major error, and now restricts arithmetic to unsigned long range.  Somehow managed to keep the size from getting out of hand, though, but it's still giving the wrong answer.
EDIT: Turns out, the result was correct but the output wasn't.  Switched to printing with %u instead of %d and all is well.  Also switched out table-based registers for variables to improve the size and speed somewhat.
EDIT: Using Lua 5.2's goto statement (also available in LuaJIT) I've replaced the interpreter with "JIT-to-Lua," generating code which is run directly by the Lua VM itself.  Not sure if this really counts as JIT, but it does improve the speed.
U,S,P,F=table.unpack,table.insert,table.remove,math.floor X,r0,r1,r2,p,m,s=2^32,0,0,0,1,0,{}C={{'r%u=%u',1,4},{'r%u=r%u',1,1},{'S(s,r%u)',1},{'r%u=P(s)',1},{'r%u=(r%u+r%u)%%X',1,0,1},{'r%u=(r%u-r%u)%%X',1,0,1},{'r%u=(r%u*r%u)%%X',1,0,1},{'r%u=F(r%u/r%u)%%X',1,0,1},{'goto L%u',4},{'m=r%u-r%u',1,1},{'if m<0 then goto L%u end',4},{'if m==0 then goto L%u end',4},{'if m>0 then goto L%u end',4},{'if m~=0 then goto L%u end',4}}t={io.open(arg[1],'rb'):read('*a'):byte(1,-1)}i,n,r=1,0,{}while i<=#t do c,i,x,a=C[t[i]+1],i+1,0,{}for j=2,#c do y=c[j]if y>0 then x=0 for k=1,y do i,x=i+1,x*256+t[i]end end S(a,x)end S(r,('::L%d::'):format(n))n=n+1 S(r,c[1]:format(U(a)))end load(table.concat(r,' '))()print(('R0 %u\nR1 %u\nR2 %u'):format(r0,r1,r2))

Here's the original, readable version.
U,S,P,F=table.unpack,table.insert,table.remove,math.floor

X,r0,r1,r2,p,m,s=2^32,0,0,0,1,0,{}

C={
    {'r%u=%u',1,4},
    {'r%u=r%u',1,1},
    {'S(s,r%u)',1},
    {'r%u=P(s)',1},
    {'r%u=(r%u+r%u)%%X',1,0,1},
    {'r%u=(r%u-r%u)%%X',1,0,1},
    {'r%u=(r%u*r%u)%%X',1,0,1},
    {'r%u=F(r%u/r%u)%%X',1,0,1},
    {'goto L%u',4},
    {'m=r%u-r%u',1,1},
    {'if m<0 then goto L%u end',4},
    {'if m==0 then goto L%u end',4},
    {'if m>0 then goto L%u end',4},
    {'if m~=0 then goto L%u end',4},
}

t={io.open(arg[1],'rb'):read('*a'):byte(1,-1)}
i,n,r=1,0,{}
while i<=#t do
    c,i,x,a=C[t[i]+1],i+1,0,{}
    for j=2,#c do
        y=c[j]
        if y>0 then
            x=0
            for k=1,y do
                i,x=i+1,x*256+t[i]
            end
        end
        S(a,x)
    end
    S(r,('::L%d::'):format(n))
    n=n+1
    S(r,c[1]:format(U(a)))
end
load(table.concat(r,' '))()
print(('R0 %u\nR1 %u\nR2 %u'):format(r0,r1,r2))

When I ran your program, I got the following error: http://pastebin.com/qQBD7Rs8 . Do you expect the bytecode over stdin or as a file?

Sorry. My binary for windows was corrupted. Thus, all the gcc/linux versions worked but the windows tests all crashed. However, it is still reporting that R0 and R1 are 0, while R2 is 1.

I suspect it isn't actually executing: it took 33.8 ms to run on average (GCC takes ~.25 seconds).

The script expects bytecode as a file, with the filename passed on the command line.  You're right though, I traced it and it looks like it's only doing the first outer loop.  Back to the drawing board...

That's what I get for thinking in C and writing in Lua:  I used < in my loops instead of <=, so the final branch instruction was left off.  It still gets the wrong answer, but now takes a few minutes to do it. :)

Worked fine on my end - Took an average of 96.718 seconds over 15 tests.

I've updated it since then -- yes, it finally gives the correct output. Notes above.

C#
1505 1475 bytes
This is my version of the interpreter, written in C# could be optimized / golfed more I think, but I don't really know where ;)
golfed version:
using System;using System.Collections.Generic;using System.IO;using System.Linq;class M{static void Main(string[]a){if(a.Length==1&&File.Exists(a[0])){B.E(B.P(File.ReadAllLines(a[0])));Console.WriteLine(B.O);}}}class B{public enum I{L=0x00,P=0x02,Q=0x03,A=0x04,S=0x05,M=0x06,D=0x07,J=0x08,C=0x09,BL=0x0a,BE=0x0b,BG=0x0c,BN=0x0d}public enum R{A,B,C}enum C{N,L,E,G}public static Dictionary<R,uint>r=new Dictionary<R,uint>{{R.A,0},{R.B,0},{R.C,0}};public static Stack<uint>s=new Stack<uint>();static C c=C.N;public static string O{get{return string.Format("R0 {0}\nR1 {1}\nR2 {2}",r[R.A],r[R.B],r[R.C]);}}public static void E(byte[][]l){for(uint i=0;i<l.Length;i++){var q=l[i];switch((I)q[0]){case I.L:r[(R)q[1]]=U(q,2);break;case I.P:r[(R)q[1]]=s.Pop();break;case I.Q:s.Push(r[(R)q[1]]);r[(R)q[1]]=0;break;case I.A:s.Push(r[(R)q[1]]+r[(R)q[2]]);break;case I.S:s.Push(r[(R)q[1]]-r[(R)q[2]]);break;case I.M:s.Push(r[(R)q[1]]*r[(R)q[2]]);break;case I.D:s.Push(r[(R)q[1]]/r[(R)q[2]]);break;case I.J:i=U(q,1)-1;break;case I.C:{uint x=r[(R)q[1]],y=r[(R)q[2]];c=x<y?C.L:x>y?C.G:C.E;}break;case I.BL:if(c==C.L)i=U(q,1)-1;break;case I.BG:if(c==C.G)i=U(q,1)-1;break;case I.BE:if(c==C.E)i=U(q,1)-1;break;case I.BN:if(c!=C.E)i=U(q,1)-1;break;}}}public static byte[][]P(string[]c){return c.Where(l=>!l.StartsWith("#")).Select(r=>r.Split(' ').Where(b=>b.Length>0).Select(b=>Convert.ToByte(b,16)).ToArray()).Where(l=>l.Length>0).ToArray();}static uint U(byte[]b,int i){return(uint)(b[i]<<24|b[i+1]<<16|b[i+2]<<8|b[i+3]);}}

edit
removed some unnecessary public and private modifiers:
using System;using System.Collections.Generic;using System.IO;using System.Linq;class M{static void Main(string[]a){if(a.Length==1&&File.Exists(a[0])){B.E(B.P(File.ReadAllLines(a[0])));Console.Write(B.O);}}}class B{enum I{L=0x00,P=0x02,Q=0x03,A=0x04,S=0x05,M=0x06,D=0x07,J=0x08,C=0x09,BL=0x0a,BE=0x0b,BG=0x0c,BN=0x0d}enum R{A,B,C}enum C{N,L,E,G}static Dictionary<R,uint>r=new Dictionary<R,uint>{{R.A,0},{R.B,0},{R.C,0}};static Stack<uint>s=new Stack<uint>();static C c=C.N;public static string O{get{return string.Format("R0 {0}\nR1 {1}\nR2 {2}\n",r[R.A],r[R.B],r[R.C]);}}public static void E(byte[][]l){for(uint i=0;i<l.Length;i++){var q=l[i];switch((I)q[0]){case I.L:r[(R)q[1]]=U(q,2);break;case I.P:r[(R)q[1]]=s.Pop();break;case I.Q:s.Push(r[(R)q[1]]);r[(R)q[1]]=0;break;case I.A:s.Push(r[(R)q[1]]+r[(R)q[2]]);break;case I.S:s.Push(r[(R)q[1]]-r[(R)q[2]]);break;case I.M:s.Push(r[(R)q[1]]*r[(R)q[2]]);break;case I.D:s.Push(r[(R)q[1]]/r[(R)q[2]]);break;case I.J:i=U(q,1)-1;break;case I.C:{uint x=r[(R)q[1]],y=r[(R)q[2]];c=x<y?C.L:x>y?C.G:C.E;}break;case I.BL:if(c==C.L)i=U(q,1)-1;break;case I.BG:if(c==C.G)i=U(q,1)-1;break;case I.BE:if(c==C.E)i=U(q,1)-1;break;case I.BN:if(c!=C.E)i=U(q,1)-1;break;}}}public static byte[][]P(string[]c){return c.Where(l=>!l.StartsWith("#")).Select(r=>r.Split(' ').Where(b=>b.Length>0).Select(b=>Convert.ToByte(b,16)).ToArray()).Where(l=>l.Length>0).ToArray();}static uint U(byte[]b,int i){return(uint)(b[i]<<24|b[i+1]<<16|b[i+2]<<8|b[i+3]);}}

call it with executable.exe filename where filename is the file containing the code to be interpreted
My "test program":
# LOAD R0 5
# CMP R0 R1
# BRANCHEQ 13
# LOAD R1 1
# LOAD R2 1
# CMP R0 R2
# MUL R1 R2
# LOAD R1 1
# ADD R2 R1
# PUSH R2
# PUSH R1
# BRANCHEQ 13
# JMP 5
# POP R2
# POP R0
# POP R1
# PUSH R0

0x0 0x0 0x0 0x0 0x0 0x5
0x9 0x0 0x1
0xb 0x0 0x0 0x0 0xd
0x0 0x1 0x0 0x0 0x0 0x1
0x0 0x2 0x0 0x0 0x0 0x1
0x9 0x0 0x2
0x6 0x1 0x2
0x0 0x1 0x0 0x0 0x0 0x1
0x4 0x2 0x1
0x2 0x2
0x2 0x1
0xb 0x0 0x0 0x0 0xd
0x8 0x0 0x0 0x0 0x5
0x3 0x2
0x3 0x0
0x3 0x1
0x2 0x0

Interpreter ungolfed with longer names variables, classes, ...
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        if (args.Length == 1 && File.Exists(args[0]))
        {
            var code = ByteCodeInterpreter.ParseCode(File.ReadAllLines(args[0]));
            ByteCodeInterpreter.Execute(code);
            Console.WriteLine(ByteCodeInterpreter.Output);
        }
    }
}

public static class ByteCodeInterpreter
{
    public enum Instruction : byte
    {
        LOAD = 0x00,
        PUSH = 0x02,
        POP = 0x03,
        ADD = 0x04,
        SUB = 0x05,
        MUL = 0x06,
        DIV = 0x07,
        JMP = 0x08,
        CMP = 0x09,
        BRANCHLT = 0x0a,
        BRANCHEQ = 0x0b,
        BRANCHGT = 0x0c,
        BRANCHNE = 0x0d
    }

    public enum Register : byte
    {
        R0 = 0x00,
        R1 = 0x01,
        R2 = 0x02
    }

    private enum CompareFlag : byte
    {
        NONE = 0x00,
        LT = 0x01,
        EQ = 0x02,
        GT = 0x03,
    }

    public static readonly Dictionary<Register, uint> register = new Dictionary<Register, uint>
    {
        {Register.R0, 0},
        {Register.R1, 0},
        {Register.R2, 0}
    };

    public static readonly Stack<uint> stack = new Stack<uint>();
    private static CompareFlag compareFlag = CompareFlag.NONE;

    public static string Output
    {
        get
        {
            return string.Format("R0 {0}\nR1 {1}\nR2 {2}", register[Register.R0], register[Register.R1],
                register[Register.R2]);
        }
    }

    public static void Execute(byte[][] lines)
    {
        for (uint i = 0; i < lines.Length; i++)
        {
            var line = lines[i];
            switch ((Instruction)line[0])
            {
                case Instruction.LOAD:
                    register[(Register)line[1]] = GetUint(line, 2);
                    break;
                case Instruction.PUSH:
                    register[(Register)line[1]] = stack.Pop();
                    break;
                case Instruction.POP:
                    stack.Push(register[(Register)line[1]]);
                    register[(Register)line[1]] = 0;
                    break;
                case Instruction.ADD:
                    stack.Push(register[(Register)line[1]] + register[(Register)line[2]]);
                    break;
                case Instruction.SUB:
                    stack.Push(register[(Register)line[1]] - register[(Register)line[2]]);
                    break;
                case Instruction.MUL:
                    stack.Push(register[(Register)line[1]] * register[(Register)line[2]]);
                    break;
                case Instruction.DIV:
                    stack.Push(register[(Register)line[1]] / register[(Register)line[2]]);
                    break;
                case Instruction.JMP:
                    i = GetUint(line, 1) - 1;
                    break;
                case Instruction.CMP:
                    {
                        uint v0 = register[(Register)line[1]], v1 = register[(Register)line[2]];
                        if (v0 < v1)
                            compareFlag = CompareFlag.LT;
                        else if (v0 > v1)
                            compareFlag = CompareFlag.GT;
                        else
                            compareFlag = CompareFlag.EQ;
                    }
                    break;
                case Instruction.BRANCHLT:
                    if (compareFlag == CompareFlag.LT)
                        i = GetUint(line, 1) - 1;
                    break;
                case Instruction.BRANCHGT:
                    if (compareFlag == CompareFlag.GT)
                        i = GetUint(line, 1) - 1;
                    break;
                case Instruction.BRANCHEQ:
                    if (compareFlag == CompareFlag.EQ)
                        i = GetUint(line, 1) - 1;
                    break;
                case Instruction.BRANCHNE:
                    if (compareFlag != CompareFlag.EQ)
                        i = GetUint(line, 1) - 1;
                    break;
            }
        }
    }

    public static byte[][] ParseCode(string[] code)
    {
        return
            code.Where(line => !line.StartsWith("#"))
                .Select(line => line.Split(' ').Where(b => b.Length > 0).Select(b => Convert.ToByte(b, 16)).ToArray())
                .Where(line => line.Length > 0)
                .ToArray();
    }

    private static uint GetUint(byte[] bytes, int index)
    {
        return (uint)(bytes[index] << 24 | bytes[index + 1] << 16 | bytes[index + 2] << 8 | bytes[index + 3]);
    }
}

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


text:
Wait, but what's e^N?
Objective:
The objective is to calculate e^N for some real or imaginary N (e.g. 2, -3i, 0.7, 2.5i, but not 3+2i). This is code golf, so, shortest code (in bytes) wins.
So, for example:

N = 3, e^N = 20.0855392
N = -2i, e^N = -0.416146837 - 0.9092974268i

The letter i shouldn't be capitalized (since in math it is lowercase)
If your language supports raising numbers to complex numbers, you can't use that. You may use built-in real exponentiation.
For any answer where b (in a + bi) is negative, it is OK to have both the plus and minus sign (e.g. 2 + -3i), since that is understood to be (2 - 3i)
Bonus (-15 bytes): Solve this for N is a any complex number (e.g. 5 + 7i). If you are going for the bonus, you can assume that both components will always be given (even for the standard objective)

Can we print a double struck i, provided we don't actually use complex arithmetic in the code?

@mmk See the image in belisarius's comment on my Mathematica answer. May the i in the output look like that, or does it have to be ASCII code 0x69?

@MartinBüttner, as long as it isn't capitalized, it is OK.

what are acceptable in/out formats? A list of 2 numbers? a+bi? r theta? native representation (APL represent complex numbers as aJb)?

And J uses ajb.

Is N always an (imaginary) integer?

Mathematica, 23 20 bytes - 15 = 5
E^#(Cos@#2+Sin@#2I)&

This is an anonymous function taking two arguments (real and imaginary component). You should supply floats unless you want exact result (with square roots and exponentials). So you can use this like
E^#(Cos@#2+Sin@#2I)&[3.0,-2.0]

Note that I is Mathematica's imaginary unit, but I'm not actually using any complex arithmetic. Also note, that Mathematica will actually print the result using a (double-struck) lowercase i as required. See the screenshot in belisarius's comment.

Perhaps there is some subtlety I don't see, but E^# (Cos@#2 + Sin@#2 I) & seems to work

@belisarius, I don't want to use I because the question asks for lowercase i, and at least Mma 10 doesn't distribute that multiplication. If you can confirm that Mma 9 does, I'll change it.

http://i.stack.imgur.com/YnPhC.png

And no, with the letter "i", it doesn't distribute

You lucky!, I cannot reduce any chars using a function in CJam :/

CJam, 22 - 15 = 7
l~_mc\ms@me:X*\X*'+@'i

Try it online here
Takes input in the form of a b where a is the real component and b is the complex.
For ex. 2i is
0 2

gives
-0.4161468365471424+0.9092974268256817i

80386 Assembly (41 bytes - 15 = 26)
8B 4C 24 04 8B 54 24 08 D9 EA DC 09 D9 C0 D9 FC DC E9 D9 C9 D9 F0 D9 E8 DE C1 D9 FD DD 02 D9 FB D8 CA DD 19 D8 C9 DD 1A C3

Floating point math in assembly is a pain..
This is a function (cdecl calling convention) that calculates e^(a+bi) via the relation e^(a+bi)=e^a cos b + e^a sin b * i. (It accepts two double * parameters, a and b in that order, and outputs the real part into the a pointer, and the imaginary part into the b pointer).
The function prototype in C would be:

void __attribute__((cdecl)) exp_complex(double *a, double *b);

About half (20, to be exact) of the 41 bytes were spent calculating e^a; another 8 were spent getting the function arguments into registers.
The above bytecode was written by hand, from the following assembly (NASM-style, commented):
; get pointers into ecx, edx
mov ecx, [esp+4] ; 8B 4C 24 04
mov edx, [esp+8] ; 8B 54 24 08

; log(2,e)
fldl2e           ; D9 EA
; a log(2,e)
fmul qword [ecx] ; DC 09
; duplicate
fld st0          ; D9 C0
; get integer part
frndint          ; D9 FC
; get fractional part
fsub st1, st0    ; DC E9
; put fractional part on top
fxch st1         ; D9 C9
; 2^(fract(a log(2,e))) - 1
f2xm1            ; D9 F0
; 2^(fract(a log(2,e)))
fld1             ; D9 E8
faddp st1        ; DE C1
; 2^(fract(a log(2,e))) * 2^(int(a log(2,e)))
; = e^a
fscale           ; D9 FD

; push b
fld qword [edx]  ; DD 02
; sin and cos
fsincos          ; D9 FB
; e^a cos b
fmul st2         ; D8 CA
; output as real part
fstp qword [ecx] ; DD 19
; e^a sin b
fmul st1         ; D8 C9
; output as imaginary part
fstp qword [edx] ; DD 1A

; exit
ret              ; C3

To try this in C (gcc, linux, intel processor):

#include <stdio.h>
#include <string.h>
#include <sys/mman.h>

int main(){
    // bytecode from earlier
    char code[] = {
        0x8B, 0x4C, 0x24, 0x04, 0x8B, 0x54, 0x24, 0x08,
        0xD9, 0xEA, 0xDC, 0x09, 0xD9, 0xC0, 0xD9, 0xFC,
        0xDC, 0xE9, 0xD9, 0xC9, 0xD9, 0xF0, 0xD9, 0xE8,
        0xDE, 0xC1, 0xD9, 0xFD, 0xDD, 0x02, 0xD9, 0xFB,
        0xD8, 0xCA, 0xDD, 0x19, 0xD8, 0xC9, 0xDD, 0x1A,
        0xC3,
    };
    // allocate executable memory to a function pointer called 'exp_complex'
    void __attribute__( (__cdecl__) ) (*exp_complex)(double *,double *) = mmap(0,sizeof code,PROT_WRITE|PROT_EXEC,MAP_ANON|MAP_PRIVATE,-1,0);
    memcpy(exp_complex, code, sizeof code);

    // test inputs
    double a = 42.24, b = -2.7182818;

    printf("%.07g + %.07g i\n", a, b);

    // call bytecode as a c function
    exp_complex(&a, &b);

    printf("%.07g + %.07g i\n", a, b);

    // release allocated memory
    munmap(exp_complex, sizeof code);

    return 0;
}

ES6, 63 56 55 bytes - 15 = 40
(a,b)=>(m=Math,e=m.exp(a),e*m.cos(b)+`+${e*m.sin(b)}i`)

This is a function that accepts a number in the form a + bi with a and b as the function arguments.
It uses Euler's formula e^ix=cosx+isinx.

You can use parentheses and the comma operator to drop return: (a,b)=>(m=Math,e=m.exp(a),e*m.cos(b)+"+"+e*m.sin(b)+"i")

You can save 1 char using template strings: (a,b)=>(m=Math,e=m.exp(a),e*m.cos(b)+\+${e*m.sin(b)}i`)`

Sorry for the almost-3-year lag, but you can save 2 char by combining variable assignment with the evaluations: (a,b)=>(e=(m=Math).exp(a))*m.cos(b)+`+${e*m.sin(b)}i`

Use with will same one more byte: with(Math)f=(a,b)=>(e=exp(a))*cos(b)+\+${e*sin(b)}i``

TI-BASIC (NSpire) 13 (28 bytes-15)
f(r,j):=^r*(sin(j)i+cos(j

The  is e. This computes e^z for z=r+i*j. i is an undefined variable. This defines a function f which accepts two parameters: the real part and the imaginary part.

i isn't an undefined variable on 83/84 calculators; I'm not sure about the Nspire. Could you check what i^2 gives on the calculator? I don't have one.

How are r and j provided ? We have to write either a function that takes input from arguments or a complete program taking input from ARGV or STDIN. I can very well write a CJam program of 0 score if I follow your approach.

i is different depending on how it's entered. Entered as a character on the keyboard it refers to the variable, while entered through a special way it refers to sqrt(-1).

@tomsmeding this works on models that actually have symbolic variables (89, 92, nspire, and the like), where a variable that isn't given a value is just a symbol. i is i and i^2 is i^2.

The added cost should be 14 for Define f(r,j)=

Haskell 30 raw, 15 with bonus:
e a b=map(*exp a)[cos b,sin b]

load it up into the GHCi, then try out the function:
Ok, modules loaded: Main.
*Main> e 3 0
[20.085536923187668,0.0]
*Main> e 0 (-2)
[-0.4161468365471424,-0.9092974268256817]

Also, humans can understand why this works :)
I hope the GHCi is a code golf legal way of bringing Haskell in.
Also note that a human must infer that the second field is the complex one.
[edit1]

CJam, 33 bytes
l_"i"&{);d_mc\ms_0<!'+*\'i}{dme}?

Test it here.
This supports only purely real or purely imaginary input.

BBC BASIC - 44 bytes (with tokenisation) - 15 = 29
Put this after the END statement. Arguments are the same as
a+bi = (a,b)

Code
DEFFNf(a,b)e=EXPa:=STR$(e*COSb)+"+"+STR$(e*SINb)+"i"

Usage
imaginary$ = FNf(1,1)
PRINT imaginary$
END
DEFFNf(a,b)e=EXPa:=STR$(e*COSb)+"+"+STR$(e*SINb)+"i"

Where the output is:
1.46869394+2.28735529i

APL (Dyalog Extended), 20 16 - 15 = 1 byte (SBCS)
'+i',⍨¨*⍤⊣×2 1○⊢

'+i',⍨¨ append "+" and "i" to the ends of
  * e to the power of
   ⊣ the left argument (the real part)
 × times
  2 1○ the cosine and sine of
   ⊢ the right argument (the imaginary part)
TryAPL online!

Python, (94 - 15) = 79 bytes
from math import *
import cmath
n=input()
print `e**(n[0])*(cos(n[1])+1j*sin(n[1]))`[1:-2]+'i'

Pretty straightforward implementation. Since python uses "j" instead of "i" for imaginary numbers, replacing the characters in the final string eats up quite a few (12) bytes. This can definitely still be golfed.
Takes input in the form of [a,b] for a + bi.

I think you can remove the space in 'print `' and why do you need cmath?

C (gcc), 51 47 bytes - 15 = 32
#define f(x)(cos((x)*1i)-1i*sin(1i*(x)))*exp(x)

Try it online!

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


text:
Looking for shorter alternatives to `range(...)`
The best solution I've found so far for a golf code puzzle I'm working on includes two rather fat-looking invocations of range.  I'm very new at code golf, especially in Python, so I could use a few tips.
The relevant fragment is this
[x for x in range(n+1,7**6)if`x`==`x`[::-1]*all(x%i for i in range(2,x))]

The upper limit of the first range is not a sharp one.  It should be at least 98690, and all else being equal (golf-wise, that is), the smaller the difference between this upper limit and 98690 the better, performance-wise1.  I'm using 76 (=117649) because 7**6 is the shortest Python expression I can come up with that fits the bill.
In contrast, the lower limit in the first range, as well as both limits in the second one, are firm.  IOW, the program (in its current form) will produce incorrect results if those limits are changed.
Is there a way to shorten one or both of the expressions
range(n+1,7**6)
range(2,x)

?
BTW, in this case, aliasing range to, say, r gains nothing:
r=range;rr
rangerange

EDIT: FWIW, the full program is this:
p=lambda n:[x for x in range(n+1,7**6)if`x`==`x`[::-1]*all(x%i for i in range(2,x))][0]

p(n) should be the smallest palindromic prime greater than n.  Also, p should not be recursive.  Warning: It is already obscenely slow!

1Yes, I know: performance is irrelevant in code golf, but that's why I wrote "all else being equal (golf-wise, that is)".  For example, my choice of 7**6, and not the more immediately obvious, but poorer-performing, "golf-equivalent" alternative 9**9.  I like to actually run my code golf attempts, which means not letting the performance degrade to the point that it would take years to run the code.  If I can help it, of course.

fwiw, you could make yours much faster for testing purposes by using generators; it's equivalent except for that: p=lambda n:(x for x in xrange(n+1,7**6)if`x`==`x`[::-1]*all(x%i for i in xrange(2,x))).next(). Of course, while your at that, might as well change xrange(2,x) to xrange(2,int(x**.5+1)) and make your testing really fast. Clearly this code is equivalent to yours, just longer and faster.

It's impossible to come up with many good golf tricks with a short fragment isolated from its context. The best-golfed programs often make surprising connections between different part of the programs. For example, a seemingly useless discarded variable may prove key, or two unrelated loops combined into one.

@feersum: I posted the whole thing (in an EDIT) quite a while ago.  It was before you posted your comment.  Didn't you see it?

@FryAmTheEggman: yes, the statement of the puzzle is that it has to be a function, and, what's worse, the function can't be recursive.

I suspect you can save characters by directly finding the lowest prime rather than finding all of them in a range and taking the lowest one. Also, what exactly is the requirement that the function can't be recursive? Can you define f recursively, then say p=f?

@xnor:there's an automated test for this that runs with a recursion limit set to ~100

@kjo I didn't refresh the page at that time...and now it is indeed shown one of the ranges was absolutely unnecessary for the actual program.

You might want to look here

Apparently this very coding challenge was already asked about on PPCG. You should look at isaacg's answer.

Make it a single loop
As is, you have two loops: one iterating over x that might be palindromic primes, another iterating over i to check if x is prime by trial division. As you noticed, loops is Python take many characters, often to write range, but also to write while _: or for x in _. So, a golfed Python solution should take pains to use as few loops as possible.
feersum's comment "The best-golfed programs often make surprising connections between different part of the programs" is very applicable here. The prime-checking might seem like a separate subroutine for which all(x%i for i in range(2,x)) is the classic expression. But we'll do it another way.
The idea is to use Wilson's Theorem. For each potential prime k, we keep a running product of (k-1)!, and check is it's a multiple of k. We can keep track of (k-1)! while we test potential k to be prime palindromes by keeping a running product P.
Actually, we'll use the stronger version of Wilson's Theorem that (k-1)! % k equals 0 for composite k and only for composite numbers, except k=4 gives 2, and so (k-1)!**2 % k equals 0 exactly for composite numbers. We'll update P to equal k!**2 via the update P*=k*k.
(See this answer for this method used to find primes in Python.)
Putting it all together:
def p(n):
 k=P=1
 while(`k`!=`k`[::-1])+(k<=n)+(P%k==0):P*=k*k;k+=1
 return k

This isn't yet fully golfed -- the condition in particular is written inefficiently.
We can compress the condition to check that k is a palindrome while at the time enforcing the other conditions via a chained inequality.
def p(n):
 k=P=1
 while`k`*(P%k>0>n-k)!=`k`[::-1]:P*=k*k;k+=1
 return k

a dazzling solution.  i'm grateful to see it, even though it goes into a realm beyond my reach...  Up to now my improvements in golf had all been a matter of picking up tricks like using backticks instead of str, but these tricks get one only so much...  the big improvements come from better algorithms, as always.

Following FryAmTheEggman's solution, one can rewrite the condition as \k`(k>n)(P%k>0)!=`k`[::-1]`, which shaves off 4

@kjo Yes, and even more similarly if you chain the inequalities into a single one. You should also check out Python Golf Practice too see tricks like this

that's very nicely done!  thank you all!  this has been a very eye-opening thread for me...  the shortest solution lengths I know of, for Python 2.7 and 3.3 are, respectively, 28 and 32 characters shorter than the version I posted originally (my absolute best effort), and when I found about this i was incredulous; i thought there had to be some foul play somewhere (e.g. by reverse engineering the automated solution-testing program).  but after seeing how the experts here quickly shaved up to 16 characters from my best effort, i am now more willing to believe those numbers.

@kjo I'm glad you're seeing the magic the magic of golfing. Are you saying there's a 55 char solution? If so, I'm intrigued. Is this an anarchy golf problem? Could you please link me to the problem statement? There might be shortcuts possible from gaps in the test cases, in particular the exception with the number 4.

the problem statement is here: http://www.checkio.org/mission/prime-palindrome-golf/, and the leader board is here: http://www.checkio.org/mission/prime-palindrome-golf/publications/ .  The length of a solution equals 250 minus the score in the leader board.  Also, note that in the original problem statement it was specified that the function be called golf (not p, as in this thread).  This explains why the best Python 3.3 solution has length 58 rather than 55.

AFAIK, not really.
Range is commonly used in python golfs because it is the shortest way to generate lists of increasing/decreasing numbers.
That said, it appears to be slightly (7 bytes) shorter to avoid using range and instead call a wrapped while loop:
def p(n):
    n+=1
    while`n`*all(n%i for i in range(2,n))!=`n`[::-1]:n+=1
    return n

Thanks to @xnor (as always) for improving the while condition's logic :)

@kjo No trouble :) You might want to add what you told me about it having to be a non-recursive function to the question, as otherwise this answer is rather poor ;)

You can save on the condition by implicitly negating it: while(\n`!=`n`[::-1])+0in(n%i for i in range(2,n)):n+=1`. I can't seem to get rid of the first pair of parens due to operator precedence issues.

Getting rid of the parens: while\n`*all(n%i for i in range(2,n))!=`n`[::-1]:n+=1`

@FryAmTheEggman: that's very sportsmanlike of you!  done

When using iterative algorithms such as Newton method or calculating fractals, where you usually need to perform iterations without actually caring about the index you can save some characters by iterating over short strings instead.
for i in range(4):x=f(x)
for i in'asdf':x=f(x)

At seven iterations this breaks even with range. For more iterations use backtics and large numbers
for i in`9**9**5`:pass

This runs 56349 times which should be enough for all practical purposes. Playing around with numbers and operators lets you hardcode a wide range of numbers this way.

While this is interesting, you can see quite clearly that he does care about the index (as the candidate prime is the index). I think this fits better as a part of this answer on the tips page instead :) (Also note that '1'*4 is shorter than 'asdf')


text:
Shortest program to split special array
Background
Imagine, you have a big array A, which is mostly zeroes, but contains a short subarray B which has only strictly positive entries. For instance:
|              A              |
[0   0   0   0   1   2   3   0]
               |     B     |

Now say, we split the array A into consecutive subarrays of length d (with a shorter final array, if the d doesn't divide the length of A). For d = 3:
[0   0   0   0   1   2   3   0]
           |           |
[0   0   0] [0   1   2] [3   0]

And now sum up each of those arrays:
[0 3 3]

And discard zero sums:
[3 3]

The Challenge
You're to write a function which prints that final array of sums in any convenient array format, given the following 5 parameters (or any subset thereof, if you don't need all of them):

The small array B.
The size of the small array B (3 in the above example).
The size of the big array A (8 in the above example).
The index where the small array begins (4 in the above example).
The length d of the subarrays (3 in the above example).

The Rules

You are not allowed to construct the big array A explicitly!
You are not allowed to construct any of the subarrays of length d explicitly!
That means you have to get the computation directly from the B and the other parameters at your disposal!

Fewest characters wins!

Can we remove/omit the inputs we don't need? As far as I can tell, I don't need size_bigarray or size_smallarray at all.

yes if you don't need it

May we construct the mini arrays that overlap with small_array? In your example, that would only be [0,1,2], 3,0]. Or none at all?

no mini arrays should be constructed

I tried to reword the spec a bit, to make the actual problem a bit more visual in the first place. Feel free to roll back the edit if you don't like it, it's just a suggestion!

@MartinBüttner Are A and B supposed to be switched in the first code block?

@hsl oops, yes...

CJam, 34 32 28 characters
{"ɚ광䃻噣攍圍숵셳ﶓ訙➰鑓쥾"2G#b126b:c~}

This is a compressed form of the following 31 bytes solution
{:D%0a*\+0\{+U):UD={0:U}*}%0-p}

This can be golfed further.
Try it online here
Input is in format of [small_array] index_where_small_array_begins divisor
For example:
[1 2 3] 5 3{"ɚ광䃻噣攍圍숵셳ﶓ訙➰鑓쥾"2G#b126b:c~}~

will give output
[1 5]

Explanation (outdated):
{                                   "Begin of function block";
 :D                                 "Store the divisor in D";
   %                                "Calculate index_where_small_array_begins%divisor";
    0a*                             "Get an array of 0 on length above number";
       \+                           "Prepend it to the small_array";
         _,{            }*          "Run this code block length(small_array) times";
            0\                      "Put 0 before small_array. This 0 marks the"
                                    "current sum of the current mini_array";
              {      }D*            "Run this code block divisor times";
               0+                   "Add 0 at the end of mini array";
                 (                  "Take out the first element from the mini array";
                  @                 "Rotate the stack to get current sum on top";
                   +                "Add the first element to the current sum";
                    \               "Swap to put current mini_array on top of stack";
                          ;]        "Pop the residual array and wrap the sums in an array";
                            0-p     "Remove 0 and print the sum_of_mini_arrays_array";
                               }    "End of function block";

CJam, 30 28 characters
{"ᘏ阋Յ꺂࠻䚉누୛伪"6e4b127b:c~}

(SE may have swallowed some unprintable characters. Please copy the code from this character counter.)
Yay for counting by characters and Unicode packing. The above string is converted to character codes, interpreted as base-216, converted to base-129, and converted back to characters, and evaluated, to give the actual code (measuring 30 bytes):
{:M%0a*\+{0\{_0a?(@+\}M*}h;]p}

This is a block, the closest thing to a function in CJam. It expects the small array, the offset, and the divisor on the stack. You can use it like
[1 2 3]4 3{"    ড숺ꤪ洽ὦ﮻ڤ綃掖迓湯"2G#b129b:c~}~

Test it here.
Explanation
:M                           "Store divisor in M.";
  %                          "Take offset modulo divisor to get R.";
   0a                        "Push [0].";
     *                       "Repeat to get R zeros.";
      \+                     "Preprend to small array.";
        {              }h    "Repeat while... leaves condition on the stack.";
         0\                  "Put a 0 underneath the array to initialise sum.";
           {        }M*      "Run the block M times.";
            _0a?             "Replace the list by [0] if it's empty.";
                (            "Split off first element.";
                 @           "Pull up current sum.";
                  +\         "And and pull list back to the top.";
                         ;   "Remove leftover empty list.";
                          ]  "Wrap sums in array.";
                           p "Print string representation to STDOUT.";

Pyth - 30 32
Edit: Fixed an error with mini array size 1 or very large offset.
D:GHYKm0GFNG~@K%/HYlGN~H1)RfTK

Defines a function : that takes small_array, index_where_small_array_begins and divisor as arguments. You can call it like:
:[1 2 3) 5 3

Returns: [1, 5]
Try it online
Explanation:
D:GHY                            : Define :
     Km0G                        : Make K an array of len(G) zeroes
         FNG             )       : for N in small_array
            ~@K%/HYlGN           : Add N to K[floor_div(H,Y)%len(G)]
                      ~H1        : Increment H
                          RfTK   : Return K without any zeroes

You can change *]0lG to m0G.

@isaacg Thanks, that's good to know :)

@isaacg I've also noticed in a few recent problems that pyth kinda loses out in some golf problems because it doesn't automatically mod indexing by the length of the collection. I looked at the source code, and this doesn't look easy to change, but it might be a good idea ;) (you might also then be able to overload @ with something else... ;p )

The only issue would be that assigning to a list could no longer use the same character as a lookup. I'll take a look.

JavaScript (ES6) 58
Function with 3 parameters
- b is the small array
- i is the index where the small array begins
- d is the dimension of the subarrays
(t is used just as a local variable)
 F=(b,i,d,t=[])=>b.map((v,p)=>t[p=(p+i%d)/d|0]=v+~~t[p])&&t

Test In FireFox/FireBug console
F([1,2,3],4,3)

Output
[ 3, 3 ]


text:
Automate xmpp requests to ESL website to challenge opponents
ESL gaming, where you can challenge players to play games. I've provided some steps you can take manually to challenge a player. Note that you have to signup for an account and have to be logged in to perform these steps. (Important: you have to sign-up for the ladder before you can challenge on that ladder too. Finally some ladders requires game guid to be added, so If you don't want to get involved with that, I suggest you signup for this ladder, and wait for admin verification, which should happen in a few hours, and you are good to go.)

The challenge
[Prerequisite]:  Figure out the technology powering the website, specifically sending the form. (The title is a hint.)

Automate whole process. Fewest bytes to achieve a challenge on a ladder wins.
[-210 bytes bonus] Make all the optional choices configurable, including:

[-40 bytes] The opponent to pick.
[-40 bytes] The ladder to challenge on.
[-30 bytes] The fields of the form.
[-100 bytes extra bonus] If you have chosen the path to take the bonus, make a nice gui to get this extra bonus.

Steps

Go to the ladder webpage: http://www.esl.eu/eu/cod4/promod/sd/1on1/ladder/.
See the list of opponents, click on one (any, eg: Hellraizer).
On the player page: http://www.esl.eu/eu/cod4/promod/sd/1on1/ladder/player/4044209/
Scroll down to see Leagues&Tournaments where you can challenge player on a ladder.

Click challenge! on a Ladder. (SD or DM pick any).
It will show a form, you don't have to fill anything, just click SEND.

Hello and welcome to PPCG! This doesn't seem to have a winning criterion, so it is off-topic for this site. Also "Figure out the technology powering the website" seems to indicate that this question is under-specified.

@FryAmTheEggman, I don't understand, I've given out 3 challenge problems, they can be weighted with points and highest point wins.

This seems awfully practical for a code golf puzzle.

Ok I edited, how about now, is it more fun/doable? @Compass

Since you seem to be trying, I retracted my close vote. In the future, try posting on our sandbox first :) That said, I still think this is too practical to be a good fit for this site.

Am I right to assume that this is your website?

No, I just play games @sudo.

Since you suggest we sign up on PokerTH and you asked a question about developing a poker game, I was suspicious.