text:
Minimal NetHack
NetHack is a roguelike game where a player must retrieve the Amulet of Yendor from the lowest level of the dungeon. Commonly played via telnet, the entire game is represented with ASCII graphics. The game is extremely challenging and requires knowledge of many game mechanics in order to succeed.
For the purposes of this challenge, assume that the entire dungeon is a single level and only 5×16 characters. Furthermore, assume that this is a "safe" dungeon or that you are only implementing a prototype—there will be no monsters, concerns about hunger, etc. In fact, you must only track the location of the character and the amulet and the game will effectively end when the player arrives at the same location as the amulet.
Challenge requirements

There will be a 5×16 dungeon (single level).
Give the player a starting location (optionally random) and the amulet a separate random (different each time the program is run) starting square inside the dungeon. That is, the amulet is not allowed to start on the same square as the player.
Accept four input keys which move the player one square at a time (four cardinal directions). Reading/processing other input is allowed (a readline() function that requires pressing 'enter', etc).
Travelling outside the bounds of the dungeon is not allowed. E.g., if the player is on the right edge of the dungeon pressing right should do nothing.
After initial generation and after each movement, print the state of the game. As this is code golf and printing is rather uninteresting, ignore the character count for the print function and function call assuming no state changes. Empty cells should be shown as period (.), amulet as double quote (") and character as at symbol (@).
The game is over when the player "discovers" the amulet (arrives at the same square)

Winning
This is a code golf challenege, the shortest code to meet the requirements one week from today will be declared winner.
Example
Here is an example solution in C# (ungolfed) to show basic requirements and sample output.
using System;

namespace nh
{
    class Program
    {
        static Random random = new Random();

        // player x/y, amulet x/y
        static int px, py, ax, ay;

        static void Main(string[] args)
        {
            px = random.Next(0, 16);
            py = random.Next(0, 5);

            // amulet starts on a position different from the player
            do { ax = random.Next(0, 16); } while (px == ax);
            do { ay = random.Next(0, 5); } while (py == ay);

            print();

            do
            {
                // reads a single keypress (no need to press enter)
                // result is cast to int to compare with character literals
                var m = (int)Console.ReadKey(true).Key;

                // Move the player. Here standard WASD keys are used.
                // Boundary checks for edge of dungeon as well.
                if (m == 'W')
                    py = (py > 0) ? py - 1 : py;
                if (m == 'S')
                    py = (py < 5) ? py + 1 : py;
                if (m == 'A')
                    px = (px > 0) ? px - 1 : px;
                if (m == 'D')
                    px = (px < 16) ? px + 1 : px;

                // print state after each keypress. If the player doesn't
                // move this is redundant but oh well.
                print();

            // game ends when player is on same square as amulet
            } while (px != ax || py != ay);
        }

        static void print()
        {
            Console.Write('\n');
            for (int y=0; y<5; y++)
            {
                for (int x = 0; x < 16; x++)
                {
                    if (x == px && y == py)
                        Console.Write('@');
                    else if (x == ax && y == ay)
                        Console.Write('"');
                    else
                        Console.Write('.');
                }
                Console.Write('\n');
            }
        }
    }
}

Total character count is 1474, but ignoring calls to the print function and its definition the final character count is 896.
Output when the program is run:
................
...."...........
..........@.....
................
................

Output (including above) after the 'a' key is pressed twice:
................
...."...........
..........@.....
................
................

................
...."...........
.........@......
................
................

................
...."...........
........@.......
................
................

The spec says the amulet should be given a separate square, but the example doesn't enforce that. Is the example valid, or should it be enforced?

I have a feeling this will be of interest to @Doorknob.

Whoops, good catch, updated. There should be a check to make sure the amulet doesn't spawn on the player.

What about buffering on stdin? A "non-blocking getchar" is very easy in some languages/environments and very hard in others. Is "press w and then enter" also OK?

Should the position of the amulet be uniform over the non-player board locations? Or just "there must be a non-zero chance of it landing on any non-player tile"? Right now, "random" could be interpreted as "randomly on one of two squares", which might be easier to implement.

Yes, that's fine. I was using Console.Read() but that was cluttering up my C# example by having to ignore newlines.

As far as random, the intent is that it's different every time you run the game, not necessary some strict uniform distribution. Pulling bits from the current time would work just as well.

Are we allowed to take input as a string of moves, e.g. "WSSAAWD"? Should we allow for the player running off an edge and compensate by sending them to the opposite side, or just prevent movement?

@Vioz- I don't see why a string of input shouldn't be allowed. If the character were to run out of bounds that should just be prevented, e.g., on the right edge pressing right should do nothing.

@tolos: Would you mind taking a look at my Julia answer and letting me know whether my scoring method is valid?

Rogue is the original roguelike game where a player must retrieve the Amulet of Yendor from the lowest level of the dungeon. Why not call this a minimal Rogue?

@Gilles I've never played Rogue but I've spent a few hours with NetHack

@Gilles Why not call this a minimal snake?

Psshh, no diagonal movement? No yubnhjkl? Not even an up staircase to climb after getting the amulet? :P (furiously upvotes anyway)

@tolos: I'm still unclear what counts as random here. It's not really possible to fulfill the different each time the program is run requirement if the program is run 80 times... Specifically, in this answer, the amulet can occupy only 9 of all possible 79 locations. Does that count?

Give the player a starting location (optionally random) Does this mean that we can choose to make the player start in the same place every time, as long as the amulet's position is random?

@Dennis I'm trying to specify the amulet should start somewhere other than the player and you shouldn't be able to, say, "move right 4, up 3" every single time to "beat" the game. Don't know a better way to word that.

@M.I.Wright Yes. I believe the python solution by Mauris does just that.

@tolos: Can I assume Caps Lock is on? I'd like to use uppercase letters for input.

It should be nice.to have a challenge asking for a little more complex roguelike game.

@Dennis That's fine. I was trying to leave input requirements a bit open and glad to see answers like the TI-BASIC submission by Thomas Kwa.

Related: http://codegolf.stackexchange.com/questions/375/build-an-engine-for-a-maze-game

TI-BASIC, 42 41 38 36 35 bytes
For your TI-83 or 84+ series graphing calculator.
int(5irand→A                          //Randomize amulet position
6log(ie^(6→C                          //15.635 + 4.093i
Repeat Ans=A                          //Ans holds the player pos. (starts bottom right)
iPart(C-iPart(C-Ans-e^(igetKey-i      //Boundary check, after adjusting player position
prgmDISPLAY
End

----------
PROGRAM:DISPLAY
For(X,0,15
For(Y,0,4
Output(Y+1,X+1,".
If A=X+Yi
Output(Y+1,X+1,"¨
If Ans=X+Yi
Output(Y+1,X+1,"@
End
End

Which direction the player will go is a function of the key code of the key pressed, but four keys that definitely work are these on the top row:
Key        [Y=]  [WINDOW]  [ZOOM]  [TRACE]  [GRAPH]
           -------------------------------------------
Key code    11      12       13               15
Direction  Left     Up     Right             Down

The amulet starts on one of the five squares in the first column, and the player starts at the bottom right square. For example, a possible arrangement is:
................
¨...............
................
................
...............@

Explanation
The player's position is stored as a complex number from 0+0i to 15+4i, where the real part goes to the right and the imaginary part goes down. This facilitates easy boundary checking on the top and left: we simply offset the number slightly and round towards zero. For example, if the offset is 0.5 and our position is -1+3i (off the screen to the left), then the position will be corrected to iPart(-0.5+3.5i)=0+3i, where it should be. Checking for the bottom and right boundaries is slightly more complicated; we need to subtract the number from a constant C, which is about 15.635 + 4.093i (it's the shortest one I could find between 15+4i and 16+5i), round, subtract from C again to flip the number back, and round again.
When a key is pressed, the unadjusted player position will move by 1 unit in some direction, but the integer part only changes when certain keys are pressed. Luckily, the keys that work are all on the top row. Below is a graph of the offsets in cases where keys 11, 12, 13, and 15 are pressed, and when no key is pressed (No press is the point inside the center square, causing the integer parts to be unchanged; the four keypresses' offsets have different integer parts). C is the red cross at the center of the circle.

Old code (42 bytes):
int(9irand→A                     // 0≤rand≤1, so int(9irand) = i*x where 0≤x≤8
1                                //set "Ans"wer variable to 1+0i
Repeat Ans=A
Ans-iPart(i^int(48ln(getKey-1    //add -i,-1,i,1 for WASD respectively (see rev. history)
Ans-int(Ans/16+real(Ans/7        //ensure player is inside dungeon
prgmDISPLAY                      //display on top 5 rows of the homescreen
                                 //(for this version switch X+Yi with Y=Xi in prgmDISPLAY)
End

Limitations
There is no way to escape a " character, so strings with a " cannot be generated inside a program. Therefore, this uses the umlaut mark ¨ instead of a quote (if there were an already-existing string with a quote mark, I could display that). To get ¨ and @ in a program, an outside tool is required; however, it is valid TI-BASIC.

Just for fun, I made this snippet that puts the diaeresis and @ symbol in Str1 (as opposed to 'an outside tool'). Pick the line at the top that matches your calculator, enter it into a new program, and run that program with Asm(.

Oh, I forgot about coding in machine code on the calculator. Don't' want to crash mine with a mistype, but I trust that it works.

CHIP-8, 48 bytes
This may not be considered legal, but why the hell not. I wrote my program in CHIP-8, a bytecode-based programming language for a virtual game console. You can try the complete program (99 bytes) in your browser using an emulator/debugger I wrote called Octo:

http://johnearnest.github.io/Octo/index.html?gist=1318903acdc1dd266469
A hex dump of that complete program is as follows:
0x60 0x14 0x61 0x04 0xC4 0x3C 0xC5 0x08
0x22 0x36 0xF6 0x0A 0x22 0x52 0x40 0x00
0x12 0x16 0x46 0x07 0x70 0xFC 0x40 0x3C
0x12 0x1E 0x46 0x09 0x70 0x04 0x41 0x00
0x12 0x26 0x46 0x05 0x71 0xFC 0x41 0x10
0x12 0x2E 0x46 0x08 0x71 0x04 0x22 0x52
0x3F 0x01 0x12 0x0A 0x00 0xFD 0xA2 0x58
0xD4 0x54 0x22 0x52 0x62 0xFF 0xA2 0x5B
0xD2 0x34 0x72 0x04 0x32 0x3F 0x12 0x40
0x62 0xFF 0x73 0x04 0x33 0x14 0x12 0x40
0x00 0xEE 0xA2 0x5F 0xD0 0x14 0x00 0xEE
0xA0 0xA0 0x40 0x00 0x00 0x20 0x00 0xF0
0x90 0x90 0xD0

You can move the player with the ASWD keys, or the 7589 keys on the original CHIP-8 keypad. If I remove all the code and data for drawing the background and the player, I instead get this 48 byte dump:
0x60 0x14 0x61 0x04 0xC4 0x3C 0xC5 0x08
0xF6 0x0A 0x40 0x00 0x12 0x12 0x46 0x07
0x70 0xFC 0x40 0x3C 0x12 0x1A 0x46 0x09
0x70 0x04 0x41 0x00 0x12 0x22 0x46 0x05
0x71 0xFC 0x41 0x10 0x12 0x2A 0x46 0x08
0x71 0x04 0x3F 0x01 0x12 0x08 0x00 0xFD

The ungolfed, complete form of the program was written in a high level assembly language as follows:
:alias px v0
:alias py v1
:alias tx v2
:alias ty v3
:alias ax v4
:alias ay v5
:alias in v6

: main
    px := 20
    py := 4
    ax := random 0b111100
    ay := random 0b001000
    draw-board
    loop
        in := key
        draw-player
        if px != 0 begin
            if in == 7 then px += -4
        end
        if px != 0x3C begin
            if in == 9 then px +=  4
        end
        if py != 0 begin
            if in == 5 then py += -4
        end
        if py != 16 begin
            if in == 8 then py +=  4
        end
        draw-player
        if vf != 1 then
    again
    exit

: draw-board
    i := amulet
    sprite ax ay 4
    draw-player
    tx := -1
    i := ground
    : draw
    loop
        sprite tx ty 4
        tx += 4
        if tx != 63 then jump draw
        tx := -1
        ty += 4
        if ty != 20 then
    again
;

: draw-player
    i := player
    sprite px py 4
;

: amulet  0xA0 0xA0 0x40
: ground  0x00 0x00 0x20 0x00
: player  0xF0 0x90 0x90 0xD0

Note that the compiled bytes themselves are the CHIP-8 programming language; the assembler is simply a more convenient means of composing such programs.

Right tool for the job.

+1 for making me waste a bunch of time playing your game over and over.

@AlexA. if you want to waste even more time you should try Cave Explorer. ASWD move in the overworld and QE are used to reset/move blocks in the platformer levels.

Great, well there goes my weekend.

I was skeptical at first, but Cave Explorer was fun and CHIP-8 has been around a lot longer than I would have guessed. So I guess I'll have to learn this.

@tolos: the Octo repository on github has lots of documentation to get you started. Drop me a line if you write anything cool!

Python 3, 86 bytes
def d():
    import sys
    for y in range(5):
        line = []
        for x in range(16):
            line.append('@' if y*16+x == p else \
                        '"' if y*16+x == a else \
                        '.')
        print(''.join(line))
    print()
    sys.stdout.flush()

p=79;a=id(9)%p
while p-a:d();p+=[p%16<15,16*(p<64),-(p%16>0),-16*(p>15)][ord(input())%7%5]

Only counting the bottom two lines, and dropping d();.

I saved another byte by starting the player in the bottom-right corner (the "last" square), then randomly sampling from the first 79 squares.

Oops, sorry, fixed! I guess I'm not amazing at manually counting bytes. :<

I think you can save another character by replacing a=id(9)%79 with a=id(9)%p.

@kirbyfan64sos Brilliant! Thanks.

Also, if you make this for Python 3, you can change the raw_input call to just input.

Oh, I'm mixing Python versions as-is anyway (print())! I'll just make it Python 3.

You may be able to save some bytes if you store y*16+x in a variable

@Levi: the entire function d() isn't part of the code golf. (y*16+x is precisely what p represents, though.)

C, 122 121 115 104 102 101 bytes
#define o ({for(int t=0;t<80;++t)t%16||putchar(10),putchar(t^p?t^a?46:34:64);})
p;main(a){for(a=1+time(0)%79;p^a;o,p+=(int[]){-16*(p>15),16*(p<64),-!!(p%16),p%16<15}[3&getchar()/2]);}

First time posting here ! I hope you like it :)
o is the printing, erm, function. Our brave hero can be moved around with 2, 4, 6 and 8, but beware of not sending any other input (no newlines !).
Update 1 : brought a and i into main's parameters.
Update 2 : OP having confirmed that a single string of input is OK, I got rid of scanf (which I used to skip the newline).
Update 3 : Used a compound array literal and modified the input layout. Program now goes haywire if you enter an invalid direction ;)
Update 4 : Noticed that the call to the printing function does not count. Took note to read rules more carefully.
Update 5 : one byte saved, thanks to Mikkel Alan Stokkebye Christia.

Could !!(p%16) be p%16>0? I don't remember my order of operations.

@ThomasKwa it is, but that unary - can't help but stick to p, so parentheses are needed either way. The double-bang is just obfuscation :)

@Quentin 3&getchar()/2 < getchar()/2-25

@MikkelAlanStokkebyeChristia thank you :)

CJam, 46 45 44 40 39 37 bytes
{'.80*W$Gb'"t1$Gb'@tG/W%N*oNo}:P;
5,G,m*:Dmr~{P_l~4b2fm.+_aD&!$_W$=!}gP];

The first line (defines a function that prints the current game state) and the P's on the second line (call that function) do not contribute to the byte count.
Both the starting position and the amulet's position are selected pseudo-randomly. The distribution is as uniform and the underlying PRNG allows.
Input is E, 6, 9 and B for Up, Down, Left and Right, with Caps Lock activated, followed by Enter.
Alternate version
{'.80*W$Gb'"t1$Gb'@tG/W%N*oNo}:P;
5,G,m*:Dmr~{P_ZYm*l~(=:(.+_aD&!$_W$=!}gP];

At the cost of four more bytes, the input format is improved significantly:

This version accepts 8, 2, 4 and 6 for Up, Down, Left and Right, which matches the corresponding arrow keys on the numpad.
It also accepts 7, 9, 1 and 3 for the corresponding diagonal moves.

Testing
Since the I/O is interactive, you should try this code with the Java interpreter.
Download the latest version and run the program like this:
java -jar cjam-0.6.5.jar nethack.cjam

To avoid pressing Enter after each key, and for in-place updates of the output, you can use this wrapper:
#!/bin/bash

lines=5
wait=0.05

coproc "$@"
pid=$!

head -$lines <&${COPROC[0]}

while true; do
    kill -0 $pid 2>&- || break
    read -n 1 -s
    echo $REPLY >&${COPROC[1]}
    printf "\e[${lines}A"
    head -$lines <&${COPROC[0]}
    sleep $wait
done

printf "\e[${lines}B"

Invoke like this:
./wrapper java -jar cjam-0.6.5.jar nethack.cjam

Main version
5,G,   e# Push [0 1 2 3 4] and [0 ... 15].
m*:D   e# Take the Cartesian product and save in D.
mr~    e# Shuffle and dump the array on the stack.
       e# This pushes 80 elements. We'll consider the bottommost the amulet's
       e# position and the topmost the player's.
{      e# Do:
  P    e#   Call P.
  _    e#   Copy the player's position.
  l~   e#   Read and evaluate one line of input.
       e#      "6" -> 6, "9" -> 9, "B" -> 11, "E" -> 14
  4b   e#   Convert to base 4.
       e#     6 -> [1 2], 9 -> [2 1], 11 -> [2 3], 14 -> [3 2]
  2f-  e#   Subtract 2 from each coordinate.
       e#     [1 2] -> [-1 0], [2 1] -> [0 -1], [2 3] -> [0 1], [3 2] -> [1 0]
  .+   e#   Add the result to the copy of player's position.
  _aD& e#   Push a copy, wrap it in an array and intersect with D.
  !    e#   Logical NOT. This pushes 1 iff the intersection was empty.
  $    e#   Copy the corresponding item from the stack.
       e#     If the intersection was empty, the new position is invalid
       e#     and 1$ copies the old position.
       e#     If the intersection was non-empty, the new position is valid
       e#     and 0$ copies the new position.
  _W$  e#   Push copies of the new position and the amulet's position.
  =!   e#   Push 1 iff the positions are different.
}g     e# While =! pushes 1.
P      e# Call P.
];     e# Clear the stack.

Alternate version
ZYm*   e# Push the Cartesian product of 3 and 2, i.e.,
       e#   [[0 0] [0 1] [0 2] [1 0] [1 1] [1 2] [2 0] [2 1] [2 2]].
l~     e#   Read and evaluate one line of input.
(=     e# Subtract 1 and fetch the corresponding element of the array.
:(     e# Subtract 1 from each coordinate.

Function P
'.80*  e# Push a string of 80 dots.
W$Gb   e# Copy the amulet's position and convert from base 16 to integer.
'"t    e# Set the corresponding character of the string to '"'.
1$Gb   e# Copy the player's position and convert from base 16 to integer.
'@t    e# Set the corresponding character of the string to '@'.
G/     e# Split into chunks of length 16.
W%     e# Reverse the chunks (only needed for the alternate program).
N*     e# Join the chunks, separating by linefeeds.
oNo    e# Print the resulting string and an additional linefeed.

I'm right on your tail with TI-BASIC! I'll post once I verify my solution.

Java, 231 bytes (196 if function)
Here's the full program code at 342:
class H{public static void main(String[]a){int p=0,y=79,c;y*=Math.random();y++;p(p,y);do p((p=(c=new java.util.Scanner(System.in).next().charAt(0))<66&p%16>0?p-1:c==68&p%16<15?p+1:c>86&p>15?p-16:c==83&p<64?p+16:p),y);while(p!=y);}static void p(int p,int y){for(int i=0;i<80;i++){System.out.print((i==p?'@':i==y?'"':'.')+(i%16>14?"\n":""));}}}

Without the print function, 231:
class H{public static void main(String[]a){int p=0,y=79,c;y*=Math.random();y++;p(p,y);do p((p=(c=new java.util.Scanner(System.in).next().charAt(0))<66&p%16>0?p-1:c==68&p%16<15?p+1:c>86&p>15?p-16:c==83&p<64?p+16:p),y);while(p!=y);}}

If just a function is okay (I'm unclear from the spec), then I can cut this down a bit further to 196:
void m(){int p=0,y=79,c;y*=Math.random();y++;p(p,y);do p((p=(c=new java.util.Scanner(System.in).next().charAt(0))<66&p%16>0?p-1:c==68&p%16<15?p+1:c>86&p>15?p-16:c==83&p<64?p+16:p),y);while(p!=y);}

And with some line breaks for a bit of clarity...
class H{
    public static void main(String[]a){
        int p=0,y=79,c;
        y*=Math.random();
        y++;p(p,y);
        do
            p(
                (p=(c=new java.util.Scanner(System.in).next().charAt(0))<66&p%16>0?
                    p-1:
                    c==68&p%16<15?
                        p+1:
                        c>86&p>15?
                            p-16:
                            c==83&p<64?
                                p+16:
                                p)
                ,y);
        while(p!=y);
    }

    static void p(int p,int y){
        for(int i=0;i<80;i++){
            System.out.print((i==p?'@':i==y?'"':'.')+(i%16>14?"\n":""));
        }
    }
}

Note that I'm not counting the print function p(p,y) itself, but I am counting the call to it, since I have stuff changing inside the call statement.
It works with capital letters ASDW. Due to the way it checks for those, some other letters might also work, but the spec doesn't really say anything about what should happen if I press different keys.

I prefer formatting nested ternary operators at the same level of indentation, as you would a chain of if/else if. It's more readable.

@ThomasKwa Yea, I've done it both ways at times. This is more like nested if statements than chained. It feels better to me because both halves of each ternary are at the same level, but distinct from the others.

If an anonymous function is acceptable you can trim your answer to  192 bytes: void m() becomes ()->

@dohaqatar7 Yea, but I don't use Java's anon functions for code golf. It feels shady to me on principle, whether or not others feel the same.

Can you do p+=?

Java, 574 bytes
import java.util.*;public class N{static Random r=new Random();static int v,b,n,m;public static void main(String[] a){v=r.nextInt(16);b=r.nextInt(5);n=r.nextInt(16);m=r.nextInt(5);p();do{Scanner e=new Scanner(System.in);char m=e.next().charAt(0);if(m=='w')b=b>0?b-1:b;if(m=='s')b=b<5?b+1:b;if(m=='a')v=v>0?v-1:v;if(m=='d')v=v<16?v+1:v;p();}while(v!=n || b!=m);}static void p(){System.out.println();for(int y=0;y<5;y++){for(int x=0;x<16;x++){if(x==z && y==x)System.out.print('@');else if(x==n && y==m)System.out.print('"');else System.out.print('.');}System.out.println();}}}

Basically the same as the C# version, except obfuscated & minimized.

so many unnecessary spaces... ;)

@Will I was just fixing that :P

Also, use one-letter names and ternaries.

@ThomasKwa fixed :D

In the C# solution, you could save a few character by declaring variables local to main (without static keyword). And I'd change the conditionals to something like px += (px < 16) ? 1 : 0;

There are still lots of unnecessary spaces and lack of ternaries ;)

Julia, 161 bytes
Uses w, a, s, and d to move up, left, down, and right, respectively.
Full code, including printing (330 bytes):
B=fill('.',5,16)
a=[rand(1:5),rand(1:16)]
B[a[1],a[2]]='"'
c=[1,a==[1,1]?2:1]
B[c[1],c[2]]='@'
for i=1:5 println(join(B[i,:]))end
while c!=a
B[c[1],c[2]]='.'
m=readline()[1]
c[2]+=m=='a'&&c[2]>1?-1:m=='d'&&c[2]<16?1:0
c[1]+=m=='w'&&c[1]>1?-1:m=='s'&&c[1]<5?1:0
m∈"wasd"&&(B[c[1],c[2]]='@')
for i=1:5 println(join(B[i,:]))end
end

Scored code, excludes printing (161 bytes):
a=[rand(1:5),rand(1:16)]
c=[1,a==[1,1]?2:1]
while c!=a
m=readline()[1]
c[2]+=m=='a'&&c[2]>1?-1:m=='d'&&c[2]<16?1:0
c[1]+=m=='w'&&c[1]>1?-1:m=='s'&&c[1]<5?1:0
end

The difference here is that we don't save the game state as a matrix; all relevant information is contained in the arrays c and a. And, of course, nothing is printed. The user will no longer be prompted for input once the player reaches the amulet.

Ungolfed + explanation (full code):
# Initialize a 5x16 matrix of dots
B = fill('.', 5, 16)

# Get a random location for the amulet
a = [rand(1:5), rand(1:16)]

# Put the amulet in B
B[a[1], a[2]] = '"'

# Start the player in the upper left unless the amulet is there
c = [1, a == [1,1] ? 2 : 1]

# Put the player in B
B[c[1], c[2]] = '@'

# Print the initial game state
for i = 1:5 println(join(B[i,:])) end

# Loop until the player gets the amulet
while c != a

    # Put a dot in the player's previous location
    B[c[1], c[2]] = '.'

    # Read a line from STDIN, take the first character
    m = readline()[1]

    # Move the player horizontally within the bounds
    if m == 'a' && c[2] > 1
        c[2] -= 1
    elseif m == 'd' && c[2] < 16
        c[2] += 1
    end

    # Move the player vertically within the bounds
    if m == 'w' && c[1] > 1
        c[1] -= 1
    elseif m == 's' && c[1] < 5
        c[1] += 1
    end

    # Set the player's new location in B
    if m ∈ "wasd"
        B[c[1], c[2]] = '@'
    end

    # Print the game state
    for i = 1:5 println(join(B[i,:])) end

end

I think that's fine

+1 for the compressed/obfuscated version looking very similar to what I remember of the actual nethack source code.

You can save a few bytes by using worse randomization:
a=[rand(1:5),1] c=a+1

@ThomasKwa: What fun is that if it's always on the first line? :)

Batch, 329 Bytes
@echo off
set e=goto e
set f= set/a
%f%a=0
%f%b=0
%f%c=%random%*3/32768+1
%f%d=%random%*16/32768+1
:et
call:p %a% %b% %c% %d%
if %a%%b% EQU %c%%d% exit/b
choice/C "wasd"
goto %errorlevel%
:1
%f%a-=1
%e%
:2
%f%b-=1
%e%
:3
%f%a+=1
%e%
:4
%f%b+=1
:e
if %a% GTR 4%f%a=4
if %a% LSS 0%f%a=0
if %b% GTR 15%f%b=15
if %b% LSS 0%f%b=0
%e%t

:p
setlocal enabledelayedexpansion
::creating a new line variable for multi line strings
set NL=^

:: Two empty lines are required here
cls
set "display="
for /l %%r in (0,1,4) do (
    set "line="
    for /l %%c in (0,1,15) do (
        set "char=."
        if %3 EQU %%r (
            if %4 EQU %%c (
                set char="
            )
        )
        if %1 EQU %%r (
            if %2 EQU %%c (
                set "char=@"
            )
        )
        set "line=!line!!char!"
    )
    set "display=!display!!line!!NL!"
)
echo !display!
exit /b

This is highly impressive. I'm surprised it's possible to do this.

This doesn't display the dungeon for me, only a series of lines prompting [W,A,S,D]?.  It does appear to "work" - walking the undisplayed dungeon eventually exits.  win7 cmd.exe

It works for me witn Win7 cmd.exe - when I type ver I get Microsoft Windows [Version 6.1.7601]

@DanPritts That's odd. It works perfectly for me on Windows 8 (Microsoft Windows [Version 6.2.9200])

doh, i hadn't copied & pasted the whole thing, i didn't scroll down in the window.    Well done.

Perl, 228 222 characters (not counting the newlines that are not integral to the working of the code) — 207 if not counting the print and print if statement parts which are used for printing, but don't add to the game logic; 144 if also considering the field representation generation code as part of printing, as suggested by Yakk in the comments)
This code uses lowercase wasd for control; input must be confirmed with Enter. Tested with Perl 5.14.2.
($a=$==rand(79))+=($a>=($==rand(80)));
print $_=("."x80)=~s/(.{$=})./\1@/r=~s/(.{$a})./\1"/r=~s/(.{16})/\1\n/gr;
%r=qw(w s/.(.{16})@/@\1./s a s/.@/@./ s s/@(.{16})./.\1@/s d s/@./.@/);
while(/"/){print if eval $r{getc STDIN}}

Note that for this code, it is impossible to separate calculation and printing, since the operations are done directly on the printed representation using regular expressions.
Explanation:
($a=$==rand(79))+=($a>=($==rand(80)));

This line determines the position of the player and the amulet. The player position is determined by $==rand(80) and is actually easy to understand: On a 5×16 board, there are 80 distinct positions where the player can be. The position is stored in the $= variable which forces the stored value into integer; this saves a few bytes for not needing to explicitly cast the result to integer (rand delivers a floating point value).
Since one of the positions is already occupied by the player, there are only 79 positions left for the amulet, therefore for the amulet's position, $a=$==rand(79) is used. Again, the assignment to $= forces a conversion to integer, however I further assign it to $a in order to reuse $= for the player's position.
Now to avoid the amulet to occupy the same position as the player, it is advanced by one position if its position is at least as large as the player's, giving an uniform distribution on the places not occupied by the player. This is achieved by $a = ($a >= $=) where $= here holds the player's position. Now the first line is generated by inserting the two initial assignments instead of the first $a$ and the only$=` in this expression.
print $_=("."x80)=~s/(.{$=})./\1@/r=~s/(.{$a})./\1"/r=~s/(.{16})/\1\n/gr;

This generates the initial field, and afterwards prints is. ("."x80) just generates a string of 80 dots. =~s/(.{$=})./\1@/r then replaces the $=th character with @, and =~s/(.{$=})./\1@/r the $ath character with ". Due to the r modifier they don't try to modify in place, but return the modified string, that's why they can be applied to the previous expressions. Finally, =~s/(.{16})/\1\n/gr inserts a newline every 16 characters. Note that the field is stored in the special variable $_ which can be used implicitly in later statements.
%r=qw(w s/.(.{16})@/@\1./s a s/.@/@./ s s/@(.{16})./.\1@/s d s/@./.@/);

This creates a hash containing the replacement rules for the different moves. A more readable version of this is
%r = ( 'w' => 's/.(.{16})@/@\1./s',
       'a' => 's/.@/@./',
       's' => 's/@(.{16})./.\1@/s',
       'd' => 's/@./.@/' );

The keys are the characters for the moves, and the values are strings containing the corresponding replacement rule.
while(/"/){print if eval"\$_=~$r{getc STDIN}"}

This is the main loop. while(/"/) checks if there is still a " character in $_ (that is, in the field). If we move onto the amulet, its character gets replaced with the player character so it disappears from the field.
eval $r{getc STDIN} reads a character from standard input, looks up the corresponding replacement rule from the has %r and applies it to $_, that is, the field. This evaluates to true if a replacement was actually made (that is, the key was found in the hash and the move was possible; an impossible move won't match in the replacement rule). In that case print is executed. Since it is called without argument, it prints $_, that is, the modified field.

Just because you include linefeeds for readability doesn't mean you have to count them. I see 228 bytes. Also, per the specific rules of this question, the printing part of your code does not contribute to the byte count.

@Dennis: For the printing part, see the explanation I've now added: You cannot meaningfully separate printing and evaluation in my code. I now changed the counting as you suggested.

Are there any state changes in your printing code?  No?  Well, in my opinion, reusing your printing code's output for your logic shouldn't penalize you.  The movement code (which is distinct!) should count, but the code that generates the "display string" shouldn't count.

@Yakk: Which part of my code do you consider the printing code? (Actually my opinion is that exclusion of the printing code from counting was a bad idea, exactly because it is not always well defined what "printing code" is.)

@celtschk ("."x80)=~s/(.{$=})./\1@/r=~s/(.{$a})./\1"/r=~s/(.{16})/\1\n/gr is pretty close at first glance, but my perl-fu is a few years rusty.  I could have missed a state change there.

@Yakk: No state change here (the regexes are all with r modifier, and the variables are only read, not written in that part). Anyway, I just noticed that in the example code, IIUC also the calls to the print function are not counted, therefore I think that the two print keywords, the if following the second print (that only controls the print itself but doesn't have an effect on the actual game logic) and the associated whitespace (that only separates those statements from the rest of the code) should not be counted. That would make 15 characters less.

C#, 256 248 234 227 226 225 bytes
Uses the NumPad arrows with NumLock turned on to move.
Indented and commented for clarity:
using System;
class P{
    static void Main(){
        int a=0,b=0,c,d,e;
        var r=new Random();
        while(0<((c=r.Next(16))&(d=r.Next(5))));
        Draw(a,b,c,d); // Excluded from the score.
        while(a!=c|b!=d){
            e=Console.ReadKey().KeyChar-48;
            a+=e==4&a>0?-1:e==6&a<15?1:0;
            b+=e==8&b>0?-1:e==2&b<4?1:0;
            Draw(a,b,c,d); // Excluded from the score.
        }
    }
    // The following method is excluded from the score.
    static void Draw(int a, int b, int c, int d){
        Console.Clear();
        for (int y = 0; y < 5; y++)
        {
            for (int x = 0; x < 16; x++)
            {
                Console.Write(
                    x == a && y == b ? '@' :
                    x == c && y == d ? '"' :
                                       '.'
                );
            }
            Console.WriteLine();
        }
    }
}

I think C# ints implicitly init to zero. Also (can't check at the moment) if casting isn't an issue you can convert character literals to ints, or at least the 'a' to 97 (I think) though the others are three digits.

Only class fields are initialised by default, and that requires them being declared static in this case.  Method variables must be initialised before first use.  That takes less characters: 4 vs 7.

Thanks @tolos for the tip on implicitly casting char to int!  Better yet, if I use the ConsoleKey enum cast as int, I can use 2-digit values.

Technically, the Main method doesn't have to be called Main, so you could shave off another three characters.

@Luaan, I think you're mistaken.  C# documentation: https://msdn.microsoft.com/en-us/library/acy3edy3.aspx

@Hand-E-Food Yeah, it's noted there - you can use the /main compiler option to change the entry point. That's why I said "technically" - as far as the code is concerned, it doesn't have to be Main. You'll have to tell the compiler the proper main method, though. Main is just the default.

Html+JavaScript(ES6), score maybe 217
Too looong, but playable online in the snippets below.
Line 6 (T.value ...) is for output and not counted (but for simplicity I counted the textarea open and close tags, even if it's output too)
As for randomness: the amulet is always in the right half of the grid and the player always start in the left half.
Click on the textArea (after enlarging it) to start and restart the game.
<textarea id=T onclick='s()' onkeyup='m(event.keyCode)'></textarea>
<script>
R=n=>Math.random()*n|0,
s=e=>m(y=R(5),x=R(8),a=R(5)*17+R(8)+8),
m=k=>(x+=(x<15&k==39)-(x>0&k==37),y+=(y<4&k==40)-(y>0&k==38),p=y*17+x,
T.value=p-a?(t=[...('.'.repeat(16)+'\n').repeat(5)],t[a]='X',t[p]='@',t.join('')):t='Well done!'
)
</script>

EcmaScript 6 Snippet (Firefox only)

R=n=>Math.random()*n|0
s=e=>m(y=R(5),x=R(8),a=R(5)*17+R(8)+8)
m=k=>(
  x+=(x<15&k==39)-(x>0&k==37),
  y+=(y<4&k==40)-(y>0&k==38),
  p=y*17+x,
  T.value=p-a?(t=[...('.'.repeat(16)+'\n').repeat(5)],t[a]='"',t[p]='@',t.join('')):t='Well done!'
)
<textarea id=T onclick='s()' onkeyup='m(event.keyCode)'></textarea>

EcmaScript 5 snippet (tested in Chrome)

function R(n) { return Math.random()*n|0 }

function s() { m(y=R(5),x=R(8),a=R(5)*17+R(8)+8) }

function m(k) {
  x+=(x<15&k==39)-(x>0&k==37)
  y+=(y<4&k==40)-(y>0&k==38)
  p=y*17+x
  T.value=p-a?(t=('.'.repeat(16)+'\n').repeat(5).split(''),t[a]='"',t[p]='@',t.join('')):t='Well done!'
}
<textarea id=T onclick='s()' onkeyup='m(event.keyCode)'></textarea>

Actionscript 3: 267 bytes
A working example is online
var a:int,p:int,t;function g(){var r=Math.random;while(p==a){a=r()*80;p=r()*80}addEventListener("keyDown",function(e){if(a==p)return;if(e.keyCode==87&&p>15)p-=16if(e.keyCode==83&&p<64)p+=16if(e.keyCode==65&&p%16>0)p--if(e.keyCode==68&&(p+1)%16>0)p++print()});print()}
Here's a complete (whitespaces included for readability) program using the game function:
package
{
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFormat;

    public class MiniRogue extends Sprite
    {
        var a:int, p:int, t;

        public function MiniRogue()
        {
            g();
        }

        function g(){
            var r=Math.random;
            while(p==a){
                a=r()*80;
                p=r()*80
            }
            addEventListener("keyDown",function(e){
                if(a==p)
                    return;
                if(e.keyCode==87&&p>15)
                    p-=16
                if(e.keyCode==83&&p<64)
                    p+=16
                if(e.keyCode==65&&p%16>0)
                    p--
                if(e.keyCode==68&&(p+1)%16>0)
                p++
                print()
            });
            print()
        }

        var old:int = -1;
        private function print():void {
            if (!t) {
                t = new TextField()
                t.defaultTextFormat = new TextFormat("_typewriter", 8)
                t.width=500;
                t.height=375;
                addChild(t)
            }
            var board:String = "";
            for (var i:int=0; i<80;i++) {
                if (i == p) {
                    board += "@";
                } else if (i == a) {
                    board += '"';
                } else {
                    board += ".";
                }
                if ((i + 1) % 16 == 0) {
                    board += "\n";
                }
            }
            if (a==p) {
                board += "Win!";
            }
            if (p == old) {
                board += "Bump!";
            }
            old = p;
            t.text = board;
        }
    }
}

Javascript: 307 216
You can play in the snippet below!
The numbers on the left are just so the console (chrome one at least) doesn't merge the rows.
To run the code:

hit "run code snippet"
hit ctrl-shift-j to open the console
click in the result section
use arrow keys and play

var x=y=2,m=Math,b=m.floor(m.random()*5),a=14,i,j,t,c=console,onload=d;function d(){c.clear();for(i=0;i<5;i++){t=i;for(j=0;j<16;j++){t+=(i==y&&j==x)?"@":(i==b&&j==a)?'"':".";if(a==x&&b==y)t=":)";}c.log(t);}}onkeydown=function(){switch(window.event.keyCode){case 37:if(x>0)x--;break;case 38:if(y>0)y--;break;case 39:if(x<15)x++;break;case 40:if(y<4)y++;break;}d();};

Un-golfed:
var px=py=2,m=Math,ay=m.floor(m.random()*5),ax=14,i,j,t,c=console,onload=draw;
function draw() {
  c.clear();
  for(i=0;i<5;i++) {
    t=i;
    for(j=0;j<16;j++) {
      t+=(i==py&&j==px)?"@":
         (i==ay&&j==ax)?'"':".";
      if(ax==px&&ay==py)t=":)";
    }
    c.log(t);
  }
}
onkeydown=function() {
  switch (window.event.keyCode) {
    case 37:
      if(px>0)px--;
      break;
    case 38:
      if(py>0)py--;
      break;
    case 39:
      if(px<15)px++;
      break;
    case 40:
      if(py<4)py++;
      break;
  }
  draw();
};

Edit 1: Read rules more carefully and rewrote my code accordingly

amulet y value is now randomized
player can no longer escape room
I no longer count the characters in the draw function or calls to it

SpecBAS - 428 402 (excluding printing, 466 425 when counted)
Uses Q/A/O/P to move up/down/left/right respectively.
The line to print the dungeon at line 1 is the only line that can be ignored, but have golfed that down a bit as well.
1 PRINT ("."*16+#13)*5
2 LET px=8: LET py=3
3 LET ax=INT(RND*16): LET ay=INT(RND*5): IF ax=px AND ay=py THEN GO TO 3
4 PRINT AT ay,ax;#34;AT py,px;"@": LET ox=px: LET oy=py: PAUSE 0: LET k$=INKEY$
5 LET px=px+(k$="p")-(k$="o")
6 IF px<0 THEN LET px=0
7 IF px>15 THEN LET px=15
8 LET py=py+(k$="a")-(k$="q")
9 IF py<0 THEN LET py=0
10 IF py>4 THEN LET py=4
11 PRINT AT oy,ox;"."
12 IF SCREEN$(px,py)<>#34 THEN GO TO 4

The reference to #34 is just a short-hand way of putting CHR$(34) in the code.
Thanks @Thomas Kwa, I hadn't noticed player start position being random was optional. Also used separate IF statements to shave off a few characters.

You may be able to save some characters by randomizing less well :2 LET px=1: LET py=1: LET ax=2: LET ay=INT(RND*5) and also using IF instead of ELSE IF.

Another C#, 221 171 170
Here is another way in C# with both positions random. Wanted to show this even if this part is 7 bytes longer than Hand-E-Food's solution.
Hand-E-Food's answer will be shorter of course as soon as he will use Console.Read().
The downside of Consol.Read is, that pressing the needed Enter causes the field to be printed 2 more times.
But I don't think there is a requirement to print just on (real) input.

Navigation is done by 8426 as in Hand-E-Foods solution.
using System;
class P
{
static void Main()
{
Func<int> n=new Random().Next;
int x=n()%16,y=n()%5,a=n()%16,b,m;
while(y==(b=n()%5));

while(x!=a|y!=b)
{
Printer.Print(a, b, x, y);  // Excluded from the score.
m=Console.Read()-48;
y+=m==8&y>0?-1:m==2&y<4?1:0;
x+=m==4&x>0?-1:m==6&x<15?1:0;
}
}
}

Edit: (added new solution and moved PrinterClass to the end)
Edit2: (changed a 14 to a 15 and saved the byte by starting on right-bottom)

Adapting the technique of Mauris it is possible to melt it down to 171 bytes in C# (of course now without both positions random):
using System;
class P
{
static void Main()
{
int p=79,a=new Random().Next()%p,m;
while(p!=a){
Printer.Print(p,a);  // Excluded from the score.
m=Console.Read()-48;
p+=m==4&p/5>0?-5:m==6&p/5<15?5:m==8&p%5>0?-1:m==2&p%5<4?1:0;
}
}
}

The Printer Class is nearly the same, just a new overload of print...
class Printer
{
    public static void Print(int ax, int ay, int px, int py)
    {
        Console.Write('\n');
        for (int y = 0; y < 5; y++)
        {
            for (int x = 0; x < 16; x++)
            {
                if (x == px && y == py)
                    Console.Write('@');
                else if (x == ax && y == ay)
                    Console.Write('"');
                else
                    Console.Write('.');
            }
            Console.Write('\n');
        }
    }

    public static void Print(int p, int a)
    {
        Print(p/5,p%5,a/5,a%5);
    }
}

Ruby, 185
Here is a Ruby example too.
I'm very new to Ruby, maybe someone knows how to do that better :)
I have counted lineFeeds as 1 since the Program will crash otherwise...
Navigation is done by 8462. You need to send input each time with enter.
def display(ax,ay,px,py)
    puts
    for y in 0..4
        for x in 0..15
            if (x == px && y == py)
                print "@"
            elsif (x == ax && y == ay)
                print '"'
            else
                print '.'
            end
        end
        puts
    end
end

x=y=0
a=Random.rand(16) while y==(b=Random.rand(5))
while x!=a or y!=b
display(a,b,x,y)  # Excluded from the score.
m=gets.chomp.to_i
y-=m==8?1:0 if y>0
y+=m==2?1:0 if y<4
x-=m==4?1:0 if x>0
x+=m==6?1:0 if x<15
end

QBasic, 103 bytes
Per the rules of the challenge, the Show subprogram is not included in the byte-count, nor is the Show p, q, a, b call (with the following newline).
b=1+TIMER MOD 9
1Show p, q, a, b
INPUT m
p=p-(m=2)*(p>0)+(m=4)*(p<4)
q=q-(m=1)*(q>0)+(m=3)*(q<15)
IF(p<>a)+(q<>b)GOTO 1

SUB Show (playerRow, playerCol, amuletRow, amuletCol)
CLS
FOR row = 0 TO 4
  FOR col = 0 TO 15
    IF row = playerRow AND col = playerCol THEN
      PRINT "@";
    ELSEIF row = amuletRow AND col = amuletCol THEN
      PRINT CHR$(34);    ' Double quote mark
    ELSE
      PRINT ".";
    END IF
  NEXT
  PRINT
NEXT
END SUB

To move, input a number and press Enter: 1 to go left, 2 to go up, 3 to go right, and 4 to go down.
This code does not output the game state at the end, when the player has found the amulet. To make it do so, add another Show p, q, a, b after the IF statement.
Explanation
Let a, b represent the coordinates of the amulet and p, q the coordinates of the player. The player starts at (0, 0), and the amulet starts on row 0, with a column between 1 and 9, inclusive, based on the 1's digit of the current time.
The rest is just a bunch of math with conditionals. The important thing to remember is that conditionals in QBasic return 0 for false, -1 for true. Let's look at the player row update statement:
p=p-(m=2)*(p>0)+(m=4)*(p<4)

If m=2, we want to move up by subtracting 1 from p, as long as p>0. Similarly, if m=4, we want to move down by adding 1 to p, as long as p<4. We can obtain the desired behavior by multiplying. If both factors are -1, their product will be 1, which we can subtract from or add to p. If either conditional is 0, the product will be 0, with no effect.
Similarly, the condition to determine whether the player has found the amulet is:
IF(p<>a)+(q<>b)GOTO 1

If either of the conditionals is true, their sum will be nonzero (either -1 or -2) and thus truthy, and the program returns to line 1. Once p equals a and q equals b, both conditionals will be 0, so their sum will be 0 and control flow can reach the end of the program.

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


text:
Shortest Wireworld

Wireworld is fun for the whole family! Your goal is to create a Wireworld implementation in the shortest amount of code possible.
A Wireworld cell can be in one of four different states, usually numbered 0–3 in software, modeled by colors in the examples here:

Empty (Black)
Electron head (Blue)
Electron tail (Red)
Conductor (Yellow)

As in all cellular automata, time proceeds in ticks. Cells behave as follows:

Empty → Empty
Electron head → Electron tail
Electron tail → Conductor
Conductor → Electron head if exactly one or two of the neighbouring cells are electron heads, or remains Conductor otherwise.

Your grid must be at least 20 by 20 and must follow the rules of Wireworld. The grid doesn't have to be colored, but make sure it follows these numbers/symbols:

Empty (0 or ' ')
Electron head (2 or 'H')
Electron tail (3 or 'T')
Conductor (1 or '_')

What does the implementation need to do? Take an input state onto the output state one tick later?

Also, beware that Mathematica and probably other languages have built-ins for cellular automata.

@xnor it needs to run on a clock and tick ever few seconds or so

does the board wrap?

As this is an unusual duplicate case, I'm going to ask a question on Meta about it.

source: Stack Exchange

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

sort: votes


text:
Recursive Binary Description
Recursive Binary Description
Recently, I made my very first contribution to OEIS by extending and adding a b-file to sequence A049064. The sequence starts with 0, and then the next values are derived from giving a "binary description" of the last item.
For example, the second term would be 10, because there was one 0 in the first element. The third term would be 1110, because there was one 1 and one 0. The fourth would be 11110. because there are three (11 in binary!) 1s and one 0. Below is a breakdown of the fifth term to make this process clear:
> 11110
> 1111 0    (split into groups of each number)
> 4*1 1*0   (get count of each number in each group)
> 100*1 1*0 (convert counts to binary)
> 100110    (join each group back together)

And here's an example for going from the 6th to the 7th term:
> 1110010110
> 111 00 1 0 11 0
> 3*1 2*0 1*1 1*0 2*1 1*0
> 11*1 10*0 1*1 1*0 10*1 1*0
> 111100111010110

You can check out a reference programφ I made to calculate the terms.
Your Job
You need to create a program or function which takes in a number n via standard input or function arguments, and prints out the sequence from the 1st term to the (n+1)th term, separated by a newline. If you would like a look at the lower numbers, you may refer to the b-file from the OEIS page. However, your program/function should support 0 <= n <= 30, i.e. up to the 31st term. This is no small feat, as A049064(30) is over 140,000 digits longδ. If you would like to see what the 31st term should be, I've put it on Pastebin.
Example I/O
func(10)
0
10
1110
11110
100110
1110010110
111100111010110
100110011110111010110
1110010110010011011110111010110
1111001110101100111001011010011011110111010110
1001100111101110101100111100111010110111001011010011011110111010110

func(0)
0

func(3)
0
10
1110
11110

There is only one rule: No standard loopholes!
This is code-golf, so the lowest byte count wins.

φ - Gist can be found here, and an ideone demo is here.
δ - Just in case you were wondering, my estimates at the length of the 100th term put it at approximately 3.28x10250 characters long, which would be quite a lot for anyone to calculate.

Output as list allowed? Like [0]\n[1, 0]\n[1, 1, 1, 0]\n...

@Jakube No, you'll need to do a string join on it.

Congrats on making a contribution to OEIS!

CJam, 18 17 bytes
0{sN1$e`2af.b}ri*

Thanks to @MartinBüttner for golfing off one byte!
Try it online in the CJam interpreter.
How it works
0                 e# Push 0.
 {           }ri* e# Repeat int(input)) times:
  s               e#   Stringify the element on top of the stack.
                       EXAMPLE: [[[1 1] '1] [[1] '0]] -> "11110"
   N              e#   Push a linefeed.
    1$            e#   Copy the last stack.
      e`          e#   Perform run-length encoding.
                  e#   EXAMPLE: "100110" -> [[1 '1] [2 '0] [2 '1] [1 '0]]
        2a        e#   Push [2].
          f.b     e#   For each pair [x 'y], execute: [x 'y][2].b
                  e#   This pushes [x2b 'y], where b is base conversion.

Pyth, 18 17 bytes
J]0VQjk~JsjR2srJ8

Try it online: Demonstration
Thanks to @isaacg for saving one byte.
Explanation:
                     implicit: Q = input number
 ]0                  create an initial list [0]
J                    and store in J
   VQ                for loop, repeat Q times:
              rJ8       run-length-encoding of J
             s          sum, unfolds lists
          jR2           convert each value to base 2
         s              sum, unfolds lists
       ~J               store the result in J

                        but return the old list,
     jk                 join it and print it

This uses the fact, that 0 and 1 in binary are also 0 and 1.

This is 1 byte shorter using V instead of .u: J]0VQjk~JsjR2srJ8

Python 2, 125 116 110 bytes
from itertools import*
v='0'
exec"print v;v=''.join(bin(len(list(g)))[2:]+k for k,g in groupby(v));"*-~input()

Saved 1 byte thanks to @Sp3000 and 5 bytes by removing a redundant int call.
Older version:
import itertools as t
v='0'
exec"print v;v=''.join(bin(int(len(list(g))))[2:]+k for k,g in t.groupby(v));"*-~input()

Saved many, many bytes thanks to @Vioz-!
Original version:
import itertools as t
v='0'
for n in range(input()+1):print v;v=''.join(bin(int(len(list(g))))[2:]+k for k,g in t.groupby(v))

K (ngn/k), 37 bytes
{,/{(,/$2\#x),*x}'(&~~':x)_x}\[;,"0"]

Try it online!

{...}\[;,"0"] set up a scan, seeded with ,"0" and run for a number of times equal to the (implicit) input

(&~~':x)_x split into groups of the same characters

{...}' for each group...

(,/$2\#x) get the binary representation of the count of each group
(...),*x append the first character of each group (i.e. whether it is a group of 0s or of 1s)

,/ flatten the results and feed to the next iteration of the scan

Ruby, 80 72 69 bytes
As a function:
f=->m{l=?0;0.upto(m){puts l;l.gsub!(/1+|0+/){$&.size.to_s(2)+$&[0]}}}

Call it for example with: f[6]

You could save a few bytes if you take input as a function argument: ->m{l=?0;0.upto(m){puts l;l.gsub!(/1+|0+/){$&.size.to_s(2)+$&[0]}}}

@blutorange Nice! Totally forgot about upto and !  -- Thanks :)

Python 2, 102 bytes
import re
o='0'
exec"print o;o=''.join(bin(len(x))[2:]+x[0]for x in re.findall('0+|1+',o));"*-~input()

Somehow the combination of itertools being longer than re and groupby returning grouper objects means that using regex is a bit shorter...

Jelly, 16 14 bytes
µṄŒrUFV€BFṾ€ø¡

Try it online!
I still feel like there's some better way to do the string printing.
-2 bytes from xigoi.

You can convert numbers to strings with Ṿ, the opposite of V.

Jelly, 9 bytes
ŒrUBFƲÐ¡Y

Try it online!
Takes input from STDIN.
Explanation
ŒrUBFƲÐ¡Y   Main niladic link
            Implicitly start with 0
      Ð¡    Repeat [number from STDIN] times and collect all values
     Ʋ      (
Œr            Run-length encode -> [[digit, repetitions], ...]
  U           Reverse each sublist -> [[repetitions, digit], ...]
   B          Convert all numbers to binary
    F         Flatten
     Ʋ      )
        Y   Join by newlines
            The numbers are automatically concatenated

Haskell, 136 130 Bytes
import Text.Printf
import Data.List
f n=putStr.unlines.take(n+1).iterate(concatMap(\n->(printf"%b"$length n)++[head n]).group)$"0"

Cobra - 128
do(i)=if(i-=1,(r=RegularExpressions).Regex.replace(f(i),'1+|0+',do(m=r.Match())=Convert.toString('[m]'.length,2)+'[m]'[:1]),'0')

Stax, 12 bytes
î╩∩▬╒«ç╚¢↓}~

Run and debug it

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


text:
Move to the printable ASCII front
Background
The move-to-front transform (MTF) is a data encoding algorithm designed to improve the performance of entropy encoding techniques.
In the bzip2 compression algorithm, it is applied after the Burrows–Wheeler transform (as seen in Burrows, Wheeler and Back), with the objective of turning groups of repeated characters into small, easily compressible non-negative integers.
Definition
For the purpose of this challenge, we'll define the printable ASCII version of the MTF as follows:
Given an input string s, take an empty array r, the string d of all printable ASCII characters (0x20 to 0x7E) and repeat the following for each character c of s:

Append the index of c in d to r.
Move c to the front of d, i.e., remove c from d and prepend it to the remainder.

Finally, we take the elements of r as indexes in the original d and fetch the corresponding characters.
Step-by-step example
INPUT: "CODEGOLF"

0. s = "CODEGOLF"
   d = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
   r = []
1. s = "ODEGOLF"
   d = "C !\"#$%&'()*+,-./0123456789:;<=>?@ABDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
   r = [35]
2. s = "DEGOLF"
   d = "OC !\"#$%&'()*+,-./0123456789:;<=>?@ABDEFGHIJKLMNPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
   r = [35 47]
3. s = "EGOLF"
   d = "DOC !\"#$%&'()*+,-./0123456789:;<=>?@ABEFGHIJKLMNPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
   r = [35 47 37]
4. s = "GOLF"
   d = "EDOC !\"#$%&'()*+,-./0123456789:;<=>?@ABFGHIJKLMNPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
   r = [35 47 37 38]
5. s = "OLF"
   d = "GEDOC !\"#$%&'()*+,-./0123456789:;<=>?@ABFHIJKLMNPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
   r = [35 47 37 38 40]
6. s = "LF"
   d = "OGEDC !\"#$%&'()*+,-./0123456789:;<=>?@ABFHIJKLMNPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
   r = [35 47 37 38 40 3]
7. s = "F"
   d = "LOGEDC !\"#$%&'()*+,-./0123456789:;<=>?@ABFHIJKMNPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
   r = [35 47 37 38 40 3 45]
8. s = ""
   d = "FLOGEDC !\"#$%&'()*+,-./0123456789:;<=>?@ABHIJKMNPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
   r = [35 47 37 38 40 3 45 41]

OUTPUT: "COEFH#MI"

Task
Write a program or function that implements the printable ASCII MTF (as defined above).
Test cases
Input:  Programming Puzzles & Code Golf
Output: Prpi"do lp%((uz rnu&3!P/o&$U$(p

Input:  NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN BATMAN!
Output: Na! !! !! !! !! !! !! !! !! !! !! !! !! !! !! !!"DDUP"%'

Input:  Two more questions and I have bzip2 in less than 100 bytes!
Output: Twp#o"si$sv#uvq(u$(l#o#W!r%w+$pz,xF%#,"x(. #0--'$GG ".z(**:

Additional rules

You cannot use any built-in operator that computes the MTF of a string.
Your code may print a trailing newline if you choose STDOUT for output.
Your code has to work for any input of 1000 or less printable ASCII characters (0x20 to 0x7E).
Standard code golf rules apply. The shortest submission in bytes wins.

"Nanananana DDUP!" just isn't as catchy as "Batman!"...

@Doorknob: But Batman isn't easily compressible.

Can we output the result in a function return instead of printing it to STDOUT?

@Fatalize: That's the most natural form of output for functions, so yes. By the way, we have defaults for I/O, so unless the question explicitly says otherwise, that's always allowed.

CJam, 20
'¡,q{_C#c' ,C+@|}fC;

Try it online
Explanation:
'¡,      make a string of characters with codes from 0 to 160 (a modified "d")
         could have been to 126 but stackexchange doesn't like the DEL character
q        read the input (s)
{…}fC    for each character C in s
  _      duplicate the d string
  C#     find the index of C in d
  c      convert to character (this is the result)
  ' ,    make a string of characters from 0 to 31
  C+     append C to the string
  @      bring d to the top
  |      set union, preserving order; effectively, C is moved to position 32
         this is the updated d string
;        pop the last d

Ostrich, 46 45 chars
Don't have a version number in the header because this is actually just the latest commit. I added the O (ascii code to string) operator after releasing the latest version (but still before this challenge was posted).
{a95,{32+O}%:d3@{:x\.3@?3@\+\x-x\+}/;{d=}%s*}

Explanation:
a             this is the "r" array (a is short for [], empty array)
95,{32+O}%:d  this is the "d" array
3@{...}/      for each character in the input (as an "argument")...
  :x            store in variable x (stack is now [r d c])
  \.3@?         find index in d     (stack is now [r d idx])
  3@\+          append index to r   (stack is now [d modified_r])
  \x-           remove char from d, and then...
  x\+           prepend char to d   (stack is now [modified_r modified_d])
;             throw away modified_d
{d=}%         map r to indices of (original) d
s*            join (s is short for ``, empty string)

I'm wondering if PPCG is turning from "code this task in the most conscise way possible in your favourite language" to "design your own programming language to solve the typical code golf task shorter than golfscript"

@AlexA. ... wait, huh, it's spelled that way? my entire life has been a lie

@JanDvorak Ostrich is almost identical to GolfScript. Only real reason I created it is because a.) GolfScript annoyingly does not have a REPL and b.) there are a few missing operators/features (floating point, I/O, etc). And language design is fun anyway!

SWI-Prolog, 239 197 189 bytes
a(S):-l([126],X),a(S,X,[],R),b(R,X).
a([A|T],X,S,R):-nth0(I,X,A,Z),(a(T,[A|Z],[I|S],R);R=[I|S]).
b([A|T],X):-(b(T,X);!),nth0(A,X,E),put(E).
l([B|R],Z):-A is B-1,X=[A,B|R],(A=32,Z=X;l(X,Z)).

Example: a(`Two more questions and I have bzip2 in less than 100 bytes!`). outputs:
Twp#o"si$sv#uvq(u$(l#o#W!r%w+$pz,xF%#,"x(. #0--'$GG ".z(**:

(and true . after it, obviously)
Note: your SWI-Prolog version has to be one of the newer ones in which the backquote ` represents codes strings. Code strings used to be represented with double-quotes " in older versions.

Python 3, 88
*d,=range(127)
for c in input():y=d.index(ord(c));d[:32]+=d.pop(y),;print(chr(y),end='')

Using some ideas from my CJam solution.
-4 bytes belong to Sp3000 :)

Python 2, 137 110 104
Wasn't hard to implement, but maybe still golfable?
Try it here
e=d=map(chr,range(32,127))
r=""
for c in raw_input():n=e.index(c);r+=d[n];e=[e[n]]+e[:n]+e[n+1:]
print r

I think you're better off doing a list map e=d=map(chr,range(32,127)) in Python 2, though you have to tweak the e to handle a list.

@xnor Thanks. I also tried using e=[e.pop(n)]+e, but it doesn't work. Why is that?

You've got e=d=, so when you pop from e you're also popping from d. Try d=e[:].

But at this point it's probably better to just do n=e.index(ord(c));r+=chr(n+32); and drop d

Stax, 18 15 14 13 bytes
ä╦@╥◄/J[;&πi⌡

Run and debug it
-3 bytes using a map, and a simpler algorithm.
-1 byte borrowing from Kevin Cruijssen's answer.
-1 byte by simplifying a stack operation.

Perl 5, 96 bytes
sub{$d=$o=join'',map chr,32..126;join'',map{$d=~s/\Q$_//;$d=$_.$d;substr$o,length$`,1}pop=~/./g}

Try it online!
Ungolfed with some explanation:
sub{
  $d=$o=join'',map chr,32..126;  #init strings d and o to chars between 0x32-0x7e
  join('',                       #join array of chars to string
    map {                        #map array of input chars
      $d=~s/\Q$_//;              #pick out current input char from d, \Q to avoid
                                 #...special regexp meaning of some chars
      $d=$_.$d;                  #prepend current input char to d
      substr$o,length$`,1        #map to char in original dict o at position of
                                 #...current input char in d
    }
    pop=~/./g                    #array of input chars
  )                              #return joined chars
}

The \Q isn't needed for the given test cases since they don't contain . (period) or other chars with special meaning in regular expressions. If they did, \Q is needed.

Pyth, 24 bytes
JK>95CM127s@LKxL~J+d-Jdz

Demonstration. Test Harness.
The first bit. JK>95CM127 sets up the necessary list and saves it to J and K. ~J+d-Jd performs the list updating, while xL ... z maps the input characters to their positions in the list. Finally, s@LK converts those indexes to characters in the original list.

Haskell, 120 bytes
e#s=[b|(b,a)<-zip[0..]s,a==e]!!0
a=[' '..'~']
f=snd.foldl(\(d,r)e->(e:take(e#d)d++tail(drop(e#d)d),r++[a!!(e#d)]))(a,[])

Usage example: f "CODEGOLF" -> "COEFH#MI"
How it works: # is an index function that returns the position of e in s (can't use Haskell's native elemIndex because of an expensive import). The main function f follows a fold pattern where it updates the position string d and result string r as it walks through the input string.

05AB1E, 16 bytes
žQDUIεXskXyìÙU}è

Output as a list of characters.
Try it online or verify all test cases.
Explanation:
žQ           # Push the printable ASCII constant string
  DU         # Duplicate it, and pop and store this copy in variable `X`
    Iε       # Map over the characters of the input:
      Xsk    #  Get the index of the current character in `X`
      Xyì    #  Then prepend the current character to `X`
         Ù   #  Uniquify the characters in this new string
          U  #  Pop and store it as new `X`
     }è      # After the map: index the mapped integers into the printable ASCII string
             # (after which the resulting character list is output implicitly)


text:
Quine permutation group
Write a program or function which, when run, outputs another program or function which is valid in the same language as the original program, and which itself will output another program or function that has the same properties. You must at one point end up back to your initial program or function.
Example
Suppose you write program A. When run, it outputs program B. When you run B, it outputs program C. When you run C, it outputs program A, thus completing the circle. A, B and C are all valid in the same language and are all different by at least one character.
Scoring
Your score is calculated as <Number of bytes of the initial program>/<number of iterations to get back to the initial program>
For instance, with the programs A, B and C in the previous example, the number of iterations is 3 (you have to run 3 times to get back to A) and the number of bytes is the number of bytes of A.
This incentivize both golfing your initial code, and having an initial program that leads to a longer chain.
The smallest score wins

This incentivizes long programs with long cycles too much.

@ThomasKwa Maybe, but I'm not sure how hard it will be to increase cycles lengths compared to the length of the initial program. I'm opened to other formulas for scoring if it turns out to favor one side too much.

How about bytes/sqrt(log(cyclelength)), or even bytes/log(log(cyclelength))?

@ThomasKwa: Yup, we need a new scoring algorithm.

Actually, even log(log(cyclelength)) is too much once this becomes a largest-number contest. The cyclelength part of the score should be bounded above.

I don't see a way to make this an interesting contest. Using sqrt(log_2(cyclelength)) capped at, say, 16 for the denominator would at least prevent arbitrarily small scores, but then Dennis' original 1e9 program would be close to the optimal score.

Could you explain the title? I can't see the connection with permutation groups.

@PeterTaylor Each program is the output of another one, and you get back to your initial program after enough runs, kinda like a Rubik's Cube. But that ends there, "Quine cycle" souded strange so I chose something innacurate but that sounds cooler

So why not use the standard term: ouroboros? Does that not sound cool enough?

@PeterTaylor I wouldn't really call that a standard term! Sounds cool but din't think about it

Or possibly just enforce a maximum length?

CJam, score → 0
{)1e9%"X$~"}0X$~

Try it online in the CJam interpreter.
The actual score of this program is obviously positive, but 1e9 can be replaced with 1e99, 1e999, 1e9999, 1e99999, etc.
The numerator of the score grows much slower than the denominator.
How it works
{          }     e# Define a block:
 )               e#   Increment the integer on the stack.
  1e9%           e#   Take the incremented integer modulo 1,000,000,000.
      "X$~"      e#   Push that string.
            0    e# Push 0.
             X$~ e# Copy the block and execute the copy.

                 e# The stack now holds the block, the modified integer and
                 e# the string "X$~", all of which CJam prints before exiting.

Executing the code prints {)1e9%"X$~"}1X$~ which, when executed, prints {)1e9%"X$~"}2X$~, etc.
After reaching {)1e9%"X$~"}999999999X$~, one more execution yields the original code.

Well that escalated quickly...

Now do you see how easy it is to make a long cycle?

@Fatalize If I make something that approaches $0$ faster, do I win. Also, Dennis, how fast does yours approach $0$, asymptotically?

@PyRulez By simply replacing the exponent in 1e9 with a larger number, the score of a program of length L is L / 10^(L - 15) for L > 15. There are unlimited ways to reduce the score faster though.

Javascript ES6, 68/1.8e16 (basically 0)
$=_=>`$=${$};$(0)`.replace(eval(`/(${_})\\)/`),x=>++_%9e15+`)`);$(0)

Based on my Bling Quine framework:
$=_=>`$=${$};$()`

Here's the output sequence starting from $(0):
$=_=>`$=${$};$(1)`.replace(eval(`/(${_})\\)/`),x=>++_%9e15+`)`);$(0)
$=_=>`$=${$};$(1)`.replace(eval(`/(${_})\\)/`),x=>++_%9e15+`)`);$(1)
$=_=>`$=${$};$(2)`.replace(eval(`/(${_})\\)/`),x=>++_%9e15+`)`);$(1)
$=_=>`$=${$};$(2)`.replace(eval(`/(${_})\\)/`),x=>++_%9e15+`)`);$(2)
$=_=>`$=${$};$(3)`.replace(eval(`/(${_})\\)/`),x=>++_%9e15+`)`);$(2)
$=_=>`$=${$};$(3)`.replace(eval(`/(${_})\\)/`),x=>++_%9e15+`)`);$(3)
$=_=>`$=${$};$(4)`.replace(eval(`/(${_})\\)/`),x=>++_%9e15+`)`);$(3)
...
$=_=>`$=${$};$(8999999999999999)`.replace(eval(`/(${_})\\)/`),x=>++_%9e15+`)`);$(8999999999999999)
$=_=>`$=${$};$(0)`.replace(eval(`/(${_})\\)/`),x=>++_%9e15+`)`);$(8999999999999999)
$=_=>`$=${$};$(0)`.replace(eval(`/(${_})\\)/`),x=>++_%9e15+`)`);$(0)

Underload, score of 0 in the limit
(a(:^)*(a(S)*):*:*:*:*^S):^

Adding another :* to the sequence of :* will add two bytes to the program, and double the period of the quine. Thus, the score can be made arbitrarily small by adding more copies.
Try it online!
This basically uses the Underload universal quine constructor (a(:^)*fS):^, which is capable of producing a program whose output is any function f of the original source code. In this case, the function in question produces a string that outputs its argument in the most naive way (by escaping it and adding a print statement; escape is a, add a print statement is (S)*); and we run the function in a loop (via ^) a power of 2 times. (2 to the power of n can be written in Underload by using n repeats of :*.) The result is output like
(((((((((((((((((a(:^)*(a(S)*):*:*:*:*^S):^)S)S)S)S)S)S)S)S)S)S)S)S)S)S)S)S

which produces, when run,
((((((((((((((((a(:^)*(a(S)*):*:*:*:*^S):^)S)S)S)S)S)S)S)S)S)S)S)S)S)S)S

and so on until the original program is reached.


text:
Dice adventure in the river Styx
You're sitting in the school cafeteria, microwaving your food like you always do around lunch. Suddenly the programming devil rises from the ashes of your burnt food and proposes a challenge:

Sup guys, I have a challenge.

How did this happen? What did you ever do wrong? Was it that one bad macro in C?
The programming devil demands a game of dice:

I demand a game of dice.

Strictly speaking, it is not a game of dice. The programming devil just wants you to calculate the mean value of throwing a die n times. The programming devil's twist is that the die can, and always will, have a number of  faces larger than n.
Challenge:
Write a program which calculates and outputs the mean value of n throws with a die with a number of faces greater than n.
Input:
Two positive integers. The first argument determines the number of throws, the second argument the number of faces of the die. There is no empty input - always two integers.
Output:
The mean value of throwing the dice n times rounded to the closest integer.
Requirements:

No output if the number of faces of the die is less than or equal to the number of throws.
The values returned from throwing the die has to be random (as close as we can get to random, that is)

The programming devil thinks this is great and will restore the burnt food of the programmer which writes the shortest code in bytes to solve his challenge:

This is a great challenge. I will restore your food if you propose the shortest program in bytes to me.

Doorknob's answer brings up a good question:  Are we actually supposed to generate a random number n times and the provide the mean, or provide the theoretical mean of rolling the dice?

You're supposed to generate n die throws of a die with a number of faces greater than n and calculate the mean value of all throws. Do you think I can clarify this better in the question somehow?

Rather than no output, can the output be something benign when faces <= throws, like 0 which is impossible in this case?

You say that "the die can, and always will, have a number of faces larger than n" but then later "No output if the number of faces of the die is less than or equal to the number of throws." Which one is it?

Does an error message count as "no output"? In TI-BASIC, error messages are displayed on top of the homescreen, so no characters are written to the homescreen.

Can we write a function which takes two arguments?

I don't think this is a duplicate of Death by Shock Probe as 1) this challenge requires the mean of the dice rolls, whereas the other challenge requires the sum and 2) this challenge has a variable number of dice, whereas the other challenge has a set number.

Ostrich 0.7.0, 18 23 chars
Two solutions, identical in length:
:x;.,{;xR*C}%_+*\/o2/+F
\:x{.R*C\}*;]_+*x/o2/+F

Edit: +5 characters to each because I forgot to round to the nearest integer.
They both actually simulate rolling the dice (and thus have non-constant output), which seems to be the intent of the challenge.
Explanation of #1:
:x;     store the number of faces in x, pop from stack
.,      create range from 0 to [number of rolls] (while keeping #rolls on stack)
{...}%  map over that range...
  ;       discard the number
  xR*     generate a float between 0 and [number of faces]
  C       take ceil, which will make this an int between 1 and [#faces]
_+*     reduce by {+} (_ is the syntax for a single-instruction block) a.k.a. sum
\/      swap top two stack elements (bringing the number of rolls to the top),
          then divide, resulting in the average

Explanation of #2:
\       bring the number of rolls to the top
:x      store number of rolls in x, but don't pop from the stack
{...}*  that many times...
  .       duplicate the number of faces
  R*C     get the random number as described in #1
  \       stick that under the number of faces again, so [#faces] is still on top
;       discard the extra [#faces]
]_+*    wrap stack in an array, sum
x/      divide by [#rolls]

These don't look like they have empty input if faces≤throws.

Are you sure this isn't Golfscript?

@BetaDecay Ostrich was designed to be as similar as possible to GolfScript. ;)

@Doorknob Cool. How much better is it?

@BetaDecay Not much. The main reason I made it is because Golfscript annoyingly doesn't have a REPL and is missing a few key operators. (see another chat link) Of course, CJam, Pyth, & co. are much better; I haven't gotten around to learning those though :P

@Doorknob Nice. Haven't checked it out, so I hope it has betters docs than Golfscript

@BetaDecay sorry... :P I should really work on those docs more someday.

@Doorknob Your definition for B is hilarious

TI-BASIC, 16 20 19 bytes
Straightforward. The +8/-1 consensus on meta is that mixing inputs is allowed—so Ans, from command-line input, is the number of faces, and N is the number of throws.
Input N
If N<Ans
int(mean(1.5+int(Ansrand(N

APL, 13 bytes
{0⍕⍺÷⍨+/?⍵⍴⍺}

This creates an unnamed dyadic function where the left argument ⍺ is the number of throws and the right argument ⍵ is the number of die faces. Here we sum (+/) ⍺ random numbers between 1 and ⍵ (?⍵⍴⍺) and divide that by ⍺ (⍺÷⍨). The result is rounded to the nearest integer (0⍕).
You can try it online.
Note that this still produces output even when the number of throws is greater than the number of faces. But per the challenge rules, that does not constitute valid input ("The die can, and always will, have a number of faces larger than n.").

This doesn't have empty output when faces≤throws.

Pyth - 17 bytes
I'm sure it can be shorter, but the checking is stopping me from putting it in a lambda.
I>QKvz.RcsmhOQKKZ

Try it here online.
Or if the second interpretation of the rules is correct, 12 bytes.
Same thing but in a lambda.
M.RcsmhOHGGZ

Try it here online.