text:
Calculate a user's privileges on CodeGolf.SE
The Challenge
Your goal is to write the shortest program possible that will take a list of events (such as upvote, downvote, etc) and return the user's reputation and the privileges that he has earned.
What sort of events?
Here is a chart of the events, listed in order of reputation earned:
-15 answer unaccepted
-10 answer unupvoted
-5  question unupvoted
-2  answer downvoted
-2  question downvoted
-2  unaccept answer
-1  downvote answer
+1  join website
+1  undownvote answer
+2  accept answer
+2  question undownvoted
+2  answer undownvoted
+5  question upvoted
+10 answer upvoted
+15 answer accepted
+100 association bonus

What sort of privileges?
Here is a list of privileges, in order of reputation required.
1 create posts
5 participate in meta
10 remove new user restrictions
10 create wiki posts
15 vote up
15 flag posts
20 talk in chat
50 comment everywhere
75 set bounties
100 edit community wiki
100 create chat rooms
125 vote down
150 create tags
200 retag questions
250 view close votes
500 cast close and reopen votes
750 established user
1000 edit questions and answers
1000 create gallery chat rooms
1250 create tag synonyms
1500 approve tag wiki edits
2000 access to moderator tools
3500 protect questions
4000 trusted user

Input
Input (on STDIN) will be a list of events, one per line, exactly how they appear in the first chart (except for the amount of reputation). A blank line represents the end of input. Here is an example (there should be a blank line at the end):
join website
association bonus
answer upvoted
answer upvoted
question upvoted
answer accepted
answer upvoted
accept answer
unaccept answer
question unupvoted
accept answer
question upvoted

Output
The first line of output (to STDOUT) should name the amount of rep accumulated. Each line after that should list one privilege earned, exactly as they appear and in the same order as the second chart. The expected output for the above input:
153 reputation
1 create posts
5 participate in meta
10 remove new user restrictions
10 create wiki posts
15 vote up
15 flag posts
20 talk in chat
50 comment everywhere
75 set bounties
100 edit community wiki
100 create chat rooms
125 vote down
150 create tags

Rules, Restrictions, and Notes
This is code golf. Standard code golf rules apply.
(EDIT: Since I have had two entries that access files, I would like to point out that the length of the file needs to be added to code length as part of the standard rules for code golf)

By “blank line at the end of the input”, do you mean that the input ends in two newline characters, or only a single one?

@MvG: I would assume one single line end.

"blank line" usually means two newline characters.

Note that the association bonus does not count towards certain priviledges, but I assume that that can be ignored for this challenge.

GolfScript (569 568 475 473 chars)
This uses non-printable characters to compress the required strings, so in xxd format:
0000000: 305c 6e2f 7b2e 2775 6e27 2f27 272a 2e2d  0\n/{.'un'/''*.-
0000010: 3162 6173 6527 6e3f 696d 646f 700a 705f  1base'n?imdop.p_
0000020: 6c27 3132 2a3d 3131 302d 4040 3d7b 7e29  l'12*=110-@@={~)
0000030: 7d2a 2b7d 2f3a 5e2e 6e27 7978 0a51 b318  }*+}/:^.n'yx.Q..
0000040: 34fd e3ad 76f0 9f48 a7db efe2 2e06 9a7a  4...v..H.......z
0000050: 0733 c726 2c43 7e1c 4bf6 bbbc dae7 3bd8  .3.&,C~.K.....;.
0000060: 835b d3b5 23ed c195 f733 6257 0741 296e  .[..#....3bW.A)n
0000070: a97c b473 e67b 3f95 5218 0256 8c58 067c  .|.s.{?.R..V.X.|
0000080: 1358 e5a6 0e7a 2894 3f26 9d0f afbc 0697  .X...z(.?&......
0000090: 9048 7845 0041 d335 0c6f e88b 0b97 e9d9  .HxE.A.5.o......
00000a0: d840 6808 c17d c1b2 5e79 f423 2436 dc33  .@h..}..^y.#$6.3
00000b0: 8da5 03d8 f563 f61a 7687 cff9 d489 24de  .....c..v.....$.
00000c0: 5a70 4966 e614 d632 d4ba c9e4 5b1e f561  ZpIf...2....[..a
00000d0: 9308 215f b7bc f475 edc0 1686 a212 d4d0  ..!_...u........
00000e0: 75c6 bab8 c4a0 1c85 d0b8 7f3f 53d1 8920  u..........?S..
00000f0: 3923 895f 15d5 6c2e 965e c295 62c7 00cd  9#._..l..^..b...
0000100: 8b46 6e2a 3d7b 9ac3 7f90 e526 b960 dbe5  .Fn*={.....&.`..
0000110: 5242 defa 24cf 5976 8378 f958 34f6 657d  RB..$.Yv.x.X4.e}
0000120: 41da 28a9 cc4f 3930 dd25 d982 3b67 9400  A.(..O90.%..;g..
0000130: 3a19 cf72 6ae9 3c19 ee5a 6fd2 ef52 e29c  :..rj.<..Zo..R..
0000140: 4872 8a86 c243 dcc1 23b1 7958 dcbc 307d  Hr...C..#.yX..0}
0000150: 7c26 67d3 dd6a fbd2 1680 4de3 156b 8a4d  |&g..j....M..k.M
0000160: ad31 d6fa 08ca 92a7 76d4 8e6e 8b71 167f  .1......v..n.q..
0000170: 3582 9d84 8038 d6c1 da9d 8b30 1805 c1aa  5....8.....0....
0000180: b05d dfe2 4474 b26f 14be fc7f ccba c499  .]..Dt.o........
0000190: 856a c31f c361 90f1 8c27 3235 3662 6173  .j...a...'256bas
00001a0: 6520 3134 3962 6173 655b 305d 2f28 3236  e 149base[0]/(26
00001b0: 2c7b 5c5b 3124 295d 2f5c 3224 3d2a 7d2f  ,{\[1$)]/\2$=*}/
00001c0: 5c2c 297b 2d7d 2b25 2b6e 257b 2761 272d  \,){-}+%+n%{'a'-
00001d0: 7e5e 5c3c 217d 2c6e 2a                   ~^\<!},n*

Modulo the string compression, the program is
0\n/{.'un'/''*.-1base'n?imdop
p_l'12*=110-@@={~)}*+}/:^.'
 reputation
1 create posts
5 participate in meta
10 remove new user restrictions
10 create wiki posts
15 vote up
15 flag posts
20 talk in chat
50 comment everywhere
75 set bounties
100 edit community wiki
100 create chat rooms
125 vote down
150 create tags
200 retag questions
250 view close votes
500 cast close and reopen votes
750 established user
1000 edit questions and answers
1000 create gallery chat rooms
1250 create tag synonyms
1500 approve tag wiki edits
2000 access to moderator tools
3500 protect questions
4000 trusted user'n%{'a'-~^\<!},n*

Pretty trivial in most respects, but there are two points of interest.
The first is the hash function for the input strings. I was astonished by how simple a hash function produces unique results for each of the 9 (once un is removed) different strings, and as a bonus it also produces a different result for the empty string, which saves stripping out the final blank line from the input.
The calculation of rep for an individual line is
.'un'/''*.-1base'n?imdop
p_l'12*=110-@@={~)}*

First, it removes un from the string, and makes a note of whether it was found. Then it applies a super-simple hash function, h(s) = ( sum over i: (-1)^i s[i] ) % 11. (You can see why I was surprised when I found it). The string
'n?imdop
p_l'

is a lookup table which maps the hash value to the change in rep (subtract 110 from the ASCII value), and then if it found un at the start it negates the change.
The second point of interest is the filter for the privileges. I tried a slightly simpler one:
{~^\<!},

which evaluates the line (undefined words do nothing) in order to get its score for comparison with the reputation (stored in ^). It almost works. The thing which breaks it is that and occurs in some of the strings, and is a pre-defined function. Solution: mangle the lines enough that and no longer occurs. (There is a case to be made that removing spaces would be better than removing the letter a, but it doesn't make any difference to the length).

The greedy search for a better substitution table actually does one character worse than my ad hoc approach. Still working on heuristics to get a non-greedy approach to run to completion before it runs out of memory.

Awesome. Can't even tell how it computes the reputation.

Ruby 1.9.3, 514 467 459 (507 460 452 + 7 for flags)
Run with ruby -rzlib <program>.
#coding:binary
r=0
$<.each{|l|b=l.sub!('un','')?-1:1
r+=('cvuwdsaifo'[/.#{l[9]||break}/].ord-2)*b}
puts"#{r} reputation"
Zlib.inflate('xÚ]QKrÃ Ýû:BìÖ“ó(XM˜`D‘lo_‰ÒL¦;ÐÓûÁ¡*AaQf(X5†X|3¬¤8Œ¨´òNé€M¨Ú]´Æ ‘³8ÞUŽøŒ]jœagmÅ_ ï˜. ˜ž®¨Ãll^WÊ
´S=U®3)ÜxËÉ=.@KÔ¶»å¨g3kónîjP™WÛžºûÂG6ÿ×ŽâÝx!;Â÷f=Z‡ÉvöhõBb¡F¶çpqíCÌ‹ñ¸PîøÕH&€·åAK{OÔ£¾Ô³Tåïqî˜’Uþý=-È™9Ÿx,¥úG8ÒÛZ#ÃB P†•ª¨\\íÂI†§Q)¼¥>¥uýËþ²d').lines{|l|l.to_i<=r&&$><<l}

If the binary string literals didn't paste properly (which they probably didn't), here's a hex dump:
0000: 23 63 6F 64 69 6E 67 3A 62 69 6E 61 72 79 0A 72   #coding:binary.r
0010: 3D 30 0A 24 3C 2E 65 61 63 68 7B 7C 6C 7C 62 3D   =0.$<.each{|l|b=
0020: 6C 2E 73 75 62 21 28 27 75 6E 27 2C 27 27 29 3F   l.sub!('un','')?
0030: 2D 31 3A 31 0A 72 2B 3D 28 27 11 63 0C 76 07 75   -1:1.r+=('.c.v.u
0040: 00 77 00 64 04 73 01 61 03 69 66 6F 27 5B 2F 2E   .w.d.s.a.ifo'[/.
0050: 23 7B 6C 5B 39 5D 7C 7C 62 72 65 61 6B 7D 2F 5D   #{l[9]||break}/]
0060: 2E 6F 72 64 2D 32 29 2A 62 7D 0A 70 75 74 73 22   .ord-2)*b}.puts"
0070: 23 7B 72 7D 20 72 65 70 75 74 61 74 69 6F 6E 22   #{r} reputation"
0080: 0A 5A 6C 69 62 2E 69 6E 66 6C 61 74 65 28 27 78   .Zlib.inflate('x
0090: DA 5D 51 4B 72 C3 20 0C DD FB 14 3A 42 EC D6 93   .]QKr. ....:B...
00A0: F3 28 58 4D 98 60 44 91 6C 8F 6F 5F 89 D2 4C A6   .(XM.`D.l.o_..L.
00B0: 3B D0 D3 FB C1 08 A1 12 2A 41 61 51 19 66 28 58   ;.......*AaQ.f(X
00C0: 35 86 58 7C 16 33 AC A4 38 8C 17 A8 B4 F2 4E 90   5.X|.3..8.....N.
00D0: E9 80 4D A8 DA 5D B4 C6 A0 91 B3 38 DE 55 8E F8   ..M..].....8.U..
00E0: 8C 5D 6A 9C 61 67 1B 6D C5 8F 5F 09 EF 1D 98 2E   .]j.ag.m.._.....
00F0: A0 98 9E AE 1E 1E A8 C3 6C 6C 5E 57 CA 0A B4 53   ........ll^W...S
0100: 3D 8F 07 55 1A AE 33 08 29 DC 78 CB 1A C9 3D 2E   =..U..3.).x...=.
0110: 40 4B D4 B6 BB E5 A8 67 33 6B F3 6E EE 6A 50 99   @K.....g3k.n.jP.
0120: 57 DB 9E BA FB C2 47 36 FF D7 8E E2 DD 13 78 21   W.....G6......x!
0130: 3B C2 F7 66 3D 5A 87 C9 76 F6 68 F5 42 62 A1 46   ;..f=Z..v.h.Bb.F
0140: B6 E7 70 71 14 ED 43 CC 8B F1 B8 50 EE F8 D5 48   ..pq..C....P...H
0150: 26 80 B7 14 E5 41 4B 7B 1A 4F D4 A3 BE D4 1B 13   &....AK{.O......
0160: B3 1C 54 E5 17 EF 71 EE 98 92 55 FE 17 FD 3D 2D   ..T...q...U...=-
0170: C8 99 39 9F 0E 78 1A 2C A5 FA 47 38 D2 1E DB 8D   ..9..x.,..G8....
0180: 5A 23 C3 42 20 11 50 86 95 17 AA A8 5C 5C ED C2   Z#.B .P.....\\..
0190: 49 86 0F A7 1A 51 29 BC A5 1A 3E 9D A5 75 13 FD   I....Q)...>..u..
01A0: CB FE 03 06 1A B2 64 27 29 2E 6C 69 6E 65 73 7B   ......d').lines{
01B0: 7C 6C 7C 6C 2E 74 6F 5F 69 3C 3D 72 26 26 24 3E   |l|l.to_i<=r&&$>
01C0: 3C 3C 6C 7D                                       <<l}

If I'm reading right, your "hashing" scheme is to concatenate the 7th and 11th characters? That's an approach I hadn't thought of, interesting.

Haskell, 787 characters
main=interact$unlines.f.z(l 0[521,471,703,455,687,320,355,0,582,93,914,682,476,244,294,545][-15,-10,-5,-2,-2,-2,-1,1,1,2,2,2,5,10,15,100].g).s
f r=[show x++" "++y|(x,y)<-(r,"reputation"):takeWhile((<=r).fst)(zip[1,5,10,10,15,15,20,50,75,100,100,125,150,200,250,500,750,1000,1000,1250,1500,2000,3500,4000].s$"A E@participate in meta@remove new I restrictions@A K E@J up@flag E@talk in C@comment everywhere@set bounties@B community K@A C G@J down@A Hs@reH F@view D Js@cast D and reopen Js@established I@B F and answers@A gallery C G@A H synonyms@approve H K Bs@access to moderator tools@protect F@trusted I">>=h)]
g x=z fromEnum x-1219
h x=l[x]['@'..]("\n":words"create edit chat close posts questions rooms tag user vote wiki")x
l d k v x=maybe d id.lookup x$zip k v
s=lines
z=(sum.).map

C# 1271 1208 1206
public class D:Dictionary<string,int>{}
void A(){
string a="answer",q="question",c="create",y="accept",x=y+"ed",u="upvote",d="downvote";
var p=new D{{c+" posts",1},{"participate in meta",5},{"remove new user restrictions",10},{c+" wiki posts",10},{"vote up",15},{"flag posts",15},{"talk in chat",20},{"comment everywhere",50},{"set bounties",75},{"edit community wiki",100},{c+" chat rooms",100},{"vote down",125},{c+" tags",150},{"retag "+q+"s",200},{"view close votes",250},{"cast close and reopen votes",500},{"established user",750},{"edit "+q+"s and "+a+"s",1000},{c+" gallery chat rooms",1000},{c+" tag synonyms",1250},{"approve tag wiki edits",1500},{"access to moderator tools",2000},{"protect "+q+"s",3500},{"trusted user",4000}};
var e=new D{{a+" un"+x,-15},{a+" un"+u+"d",-10},{q+" un"+u+"d",-5},{a+" "+d+"d",-2},{q+" "+d+"d ",-2},{"un"+y+" "+a,-2},{d+" "+a,-1},{"join website",1},{"un"+d+" "+a,1},{y+" "+a,2},{q+" un"+d+"d",2},{a+" un"+d+"d",2},{q+" "+u+"d",5},{a+" "+u+"d",10},{a+" "+x,15},{"association bonus",100}};
var s=0;
for(var l=Console.ReadLine();l!="";l=Console.ReadLine())s+=e[l];
Console.WriteLine(s+" reputation");foreach(var i in p.Where(i=>i.Value<=s))Console.WriteLine(i.Key);}

C - 1083 1069
I realize that I'm a bit late to the game, but C's not represented, so I figured I'd take a stab at it.

#include <stdio.h>
H(char*c){int h,n;for(h=n=0;*c!=0;++n,++c)h=(h^*c)+n;return h;}
main(){int h,r=0,R[483];R[110]=-15;R[122]=-10;R[153]=2;R[157]=1;R[189]=-2;R[20]=-2;R[235]=5;R[238]=15;R[28]=10;R[30]=2;R[351]=-5;R[388]=100;R[482]=-2;R[52]=2;R[77]=-1;R[87]=1;char L[99];while(h=H(gets(&L)))r+=R[h];
#define G(x)if(r<x)goto E;
#define P(x)printf("%s\n",x);
P("1 create posts")G(5)P("5 participate in meta")G(10)P("10 remove new user restrictions\n10 create wiki posts")G(15)P("15 vote up\n15 flag posts")G(20)P("20 talk in chat")G(50)P("50 comment everywhere")G(75)P("75 set bounties")G(100)P("100 edit community wiki\n100 create chat rooms")G(125)P("125 vote down")G(150)P("150 create tags")G(200)P("200 retag questions")G(250)P("250 view close votes")G(500)P("500 cast close and reopen votes")G(750)P("750 established user")G(1000)P("1000 edit questions and answers\n1000 create gallery chat rooms")G(1250)P("1250 create tag synonyms")G(1500)P("1500 approve tag wiki edits")G(2000)P("2000 access to moderator tools")G(3500)P("3500 protect questions")G(4000)P("4000 trusted user")E:}

#include <stdio.h>
H(char*c){int h,n;for(h=n=0;*c;++n,++c)h=(h^*c)+n;return h;}
main(){int h,r=0,R[483];R[110]=-15;R[122]=-10;R[153]=2;R[157]=1;R[189]=-2;R[20]=-2;R[235]=5;R[238]=15;R[28]=10;R[30]=2;R[351]=-5;R[388]=100;R[482]=-2;R[52]=2;R[77]=-1;R[87]=1;char L[99];while(h=H(gets(&L)))r+=R[h];
#define G(x)if(r<x)return;
#define P(x)puts(x);
P("1 create posts")G(5)P("5 participate in meta")G(10)P("10 remove new user restrictions\n10 create wiki posts")G(15)P("15 vote up\n15 flag posts")G(20)P("20 talk in chat")G(50)P("50 comment everywhere")G(75)P("75 set bounties")G(100)P("100 edit community wiki\n100 create chat rooms")G(125)P("125 vote down")G(150)P("150 create tags")G(200)P("200 retag questions")G(250)P("250 view close votes")G(500)P("500 cast close and reopen votes")G(750)P("750 established user")G(1000)P("1000 edit questions and answers\n1000 create gallery chat rooms")G(1250)P("1250 create tag synonyms")G(1500)P("1500 approve tag wiki edits")G(2000)P("2000 access to moderator tools")G(3500)P("3500 protect questions")G(4000)P("4000 trusted user")}

Here's a slightly less golfed version:
#include <stdio.h>
int hash(char * c){int h,n;for(h=n=0;*c!=0;++n,++c)h=(h^*c)+n;return h;}
int main(int argc, char *argv[])
{
int R[483];
R[110]=-15;// answer unaccepted
R[122]=-10;// answer unupvoted
R[153]=2;  // question undownvoted
R[157]=1;  // join website
R[189]=-2; // question downvoted
R[20]=-2;  // answer downvoted
R[235]=5;  // question upvoted
R[238]=15; // answer accepted
R[28]=10;  // answer upvoted
R[30]=2;   // answer undownvoted
R[351]=-5; // question unupvoted
R[388]=100;// association bonus
R[482]=-2; // unaccept answer
R[52]=2;   // accept answer
R[77]=-1;  // downvote answer
R[87]=1;   // undownvote answer
int h,r=0;
char L[99];
while(h=hash(gets(&L)))r+=R[h];
#define G(x)if(r<x)goto end;
#define P(x)printf("%s\n",x);
P("1 create posts")
G(5)
P("5 participate in meta")
G(10)
P("10 remove new user restrictions")
P("10 create wiki posts")
G(15)
P("15 vote up")
P("15 flag posts")
G(20)
P("20 talk in chat")
G(50)
P("50 comment everywhere")
G(75)
P("75 set bounties")
G(100)
P("100 edit community wiki")
P("100 create chat rooms")
G(125)
P("125 vote down")
G(150)
P("150 create tags")
G(200)
P("200 retag questions")
G(250)
P("250 view close votes")
G(500)
P("500 cast close and reopen votes")
G(750)
P("750 established user")
G(1000)
P("1000 edit questions and answers")
P("1000 create gallery chat rooms")
G(1250)
P("1250 create tag synonyms")
G(1500)
P("1500 approve tag wiki edits")
G(2000)
P("2000 access to moderator tools")
G(3500)
P("3500 protect questions")
G(4000)
P("4000 trusted user")
end:
return 0;
}

I think the basic idea is similar to many other people's approaches. I use a little home-made hash to deal with recognizing inputs. The hash conveniently gives zero for an empty string, making the input-reading line very compact. I'm sure that the hash could be greatly improved. Some good character savings could be gotten by allowing some strategic hash collisions for things that have the same reputation.

I also had some real perverse fun hiding a goto inside a macro (my first time ever using a goto, I'm proud to say).

The one place where I'm sure I have a lot of room for improvement is in the output section. I haven't even attempted to compress the actual printing logic, so I'm sure that I could save some characters there as well.

You could use puts instead of printf.

Also, you can replace goto E with return (eliminating the label) and remove the !=0 in the hash function (it's redundant).

Hope you don't mind a bit of competition.

C (765 737 chars)
#define P(x,m) if(s>=x)puts(#x" "#m);
s;char*e="&g 5 x$hg54  $  G5UC vg",l[99];main(){while(gets(l))s+=e[(l[11]%8^l[7])-97]*7%118-15;printf("%d reputation\n",s);P(1,create posts)P(5,participate in meta)P(10,remove new user restrictions)P(10,create wiki posts)P(15,vote up)P(15,flag posts)P(20,talk in chat)P(50,comment everywhere)P(75,set bounties)P(100,edit community wiki)P(100,create chat rooms)P(125,vote down)P(150,create tags)P(200,retag questions)P(250,view close votes)P(500,cast close and reopen votes)P(750,established user)P(1000,edit questions and answers)P(1000,create gallery chat rooms)P(1250,create tag synonyms)P(1500,approve tag wiki edits)P(2000,access to moderator tools)P(3500,protect questions)P(4000,trusted user)}

Or a bit more readable with added linebreaks and indentation:
#define P(x,m) if(s>=x)puts(#x" "#m);
s;char*e="&g 5 x$hg54  $  G5UC vg",l[99];
main(){
 while(gets(l))s+=e[(l[11]%8^l[7])-97]*7%118-15;
 printf("%d reputation\n",s);
 P(1,create posts)
 P(5,participate in meta)
 P(10,remove new user restrictions)
 P(10,create wiki posts)
 P(15,vote up)
 P(15,flag posts)
 P(20,talk in chat)
 P(50,comment everywhere)
 P(75,set bounties)
 P(100,edit community wiki)
 P(100,create chat rooms)
 P(125,vote down)
 P(150,create tags)
 P(200,retag questions)
 P(250,view close votes)
 P(500,cast close and reopen votes)
 P(750,established user)
 P(1000,edit questions and answers)
 P(1000,create gallery chat rooms)
 P(1250,create tag synonyms)
 P(1500,approve tag wiki edits)
 P(2000,access to moderator tools)
 P(3500,protect questions)
 P(4000,trusted user)
}

The above codes assumes a single newline at the end of the file. If there are two, then one needs to write s+=*l?e[…]:0 instead of s+=e[…], at an additional cost of 5 chars. Writing while(*gets(l)) would be shorter but won't work since I don't include headers, so the compiler assumes gets returns int not char*.
The hashing expression (l[11]%8^l[7])-97 was found by trying all expressions of the following forms, looking for the one with shortest resulting code length:
for i in range(13):
    for j in range(13):
        pat("a[i]^a[j]", i=i, j=j)
        pat("a[i]-a[j]", i=i, j=j)
        pat("a[i]|a[j]", i=i, j=j)
        pat("a[i]&a[j]", i=i, j=j)
        pat("a[i]*a[j]", i=i, j=j)
        pat("a[i]%a[j]", i=i, j=j)
        for k in range(13):
            pat("a[i]^a[j]^a[k]", i=i, j=j, k=k)
            pat("a[i]%a[j]^a[k]", i=i, j=j, k=k)
            pat("a[i]*a[j]^a[k]", i=i, j=j, k=k)
            pat("a[i]+a[j]^a[k]", i=i, j=j, k=k)
            pat("a[i]-a[j]^a[k]", i=i, j=j, k=k)
            pat("a[i]^a[j]|a[k]", i=i, j=j, k=k)
            pat("a[i]%a[j]|a[k]", i=i, j=j, k=k)
            pat("a[i]*a[j]|a[k]", i=i, j=j, k=k)
            pat("a[i]+a[j]|a[k]", i=i, j=j, k=k)
            pat("a[i]-a[j]|a[k]", i=i, j=j, k=k)
            pat("a[i]*k^a[j]", i=i, j=j, k=k)
            pat("a[i]%k^a[j]", i=i, j=j, k=k)
            pat("a[i]%k+a[j]", i=i, j=j, k=k)
            pat("a[i]%k-a[j]", i=i, j=j, k=k)
            pat("a[i]%k|a[j]", i=i, j=j, k=k)
            for l in range(13):
                pat("a[i]%k^a[j]%l", i=i, j=j, k=k, l=l)
        for k in range(100):
            pat("a[i]+k^a[j]", i=i, j=j, k=k)
            pat("a[i]-k^a[j]", i=i, j=j, k=k)

A suitable printable ASCII character representation was found using a similar brute force search.
Python 3 (743 715 chars)
In the same spirit as above. This one relies on a second newline at the end of the input, though.
s=0
while 1:
 l=input()
 if not l:break
 s+=b'>-/1/.04-1*//0//91%\x93/ -'[(ord(l[11])%8^ord(l[7]))-97]-47
print(s,"reputation")
for p in "1 create posts|5 participate in meta|10 remove new user restrictions|10 create wiki posts|15 vote up|15 flag posts|20 talk in chat|50 comment everywhere|75 set bounties|100 edit community wiki|100 create chat rooms|125 vote down|150 create tags|200 retag questions|250 view close votes|500 cast close and reopen votes|750 established user|1000 edit questions and answers|1000 create gallery chat rooms|1250 create tag synonyms|1500 approve tag wiki edits|2000 access to moderator tools|3500 protect questions|4000 trusted user".split("|"):
 if s>=int(p.split(" ")[0]):print(p)

723 bytes

Java - 1519 chars
import java.util.*;public class A{static List m=new ArrayList();static String c="create",p="posts",w="wiki",e="edit",v="vote",t="tag",q="questions";
static void g(String a){m.add(a);}public static void main(String a[]){
g("1 "+c+" "+p);g("5 participate in meta");g("10 remove new user restrictions");g("10 "+c+" "+w+" "+p);g("15 "+v+" up");g("15 flag "+p);g("20 talk in chat");g("50 comment everywhere");g("75 set bounties");g("100 "+e+" community "+w);g("100 "+c+" chat rooms");g("125 "+v+" down");g("150 "+c+" "+t+"s");g("200 re"+t+" "+q);g("250 view close "+v+"s");g("500 cast close and reopen "+v+"s");g("750 established user");g("1000 "+e+"s "+q+" and answers");g("1000 "+c+" gallery chat rooms");g("1250 "+c+" "+t+" synonyms");g("1500 approve "+t+" "+w+" "+e+"s");g("2000 access to moderator tools");g("3500 protect "+q);g("4000 trusted user");
Scanner s=new Scanner(System.in);String i=s.nextLine();int r=0;int b;
while(!i.equals("")){b=r(i);if(b==1740)r-=15;if(b==1690)r-=10;if(b==1922)r-=5;if(b==1674||b==1906||b==1539)r-=2;if(b==1574)r-=1;if(b==1219||b==1801)r+=1;if(b==1312||b==2133||b==1901)r+=2;if(b==1695)r+=5;if(b==1463)r+=10;if(b==1513)r+=15;if(b==1764)r+=100;i=s.nextLine();}
System.out.println(r+" reputation");for(Object q:m)if(c(q,r))System.out.println((String)q);}
static boolean c(Object q,int r){StringTokenizer t=new StringTokenizer((String)q);if(Integer.parseInt(t.nextToken())<=r)return true;return false;}
static int r(String i){int r=0;for(int k=0;k<i.length();)r+=i.charAt(k++);return r;}}

To find reputation, it adds all the character in input string (example 'join website' adds to form 1219) and when b==1219, r=r+1.

It's 1518 chars, not 1519. Removing new lines reduces it to 1511. Answer can further be improved because method c does an if check to decide whether a true or a false should be returned where as this boolean from the if can directly be returned to bring the size down to 1470 ;) I have suggested an improvement for your answer. It's awaiting peer review :)

My edit (for some reason) wasn't accepted. I reposted my answer as a post [not something I'd like but I didn't see any other way :(]. Link: http://codegolf.stackexchange.com/a/18478/14156

Scala 1089
object R extends App{val t=List(("j.*",1),(".*s",100),(".*r a.*",15),(".*r d.*",-2),(".*n d.*",-2),(".* una.*",-15),("u.*",-2),("ac.*",2),("und.*",1),("d.*",-1),(".*r up.*",10),(".*n up.*",5),(".*r unu.*",-10),(".*r .*",2),(".*n unu.*",-5),(".*n .*",2))
def a(s:String)=t.find(x=>s.matches(x._1)).map(x=>x._2).getOrElse(0)
var(r,s)=(0,"")
do{s=readLine
r+=a(""+s)}while(s!=null)
println(r+" reputation")
val (q,c)=(" questions","create ")
val d=List(1->(c+"posts"),5->"participate in meta",10->"remove new user restrictions",10->(c+"wiki posts"),15->"vote up",15->"flag posts",20->"talk in chat",50->"comment everywhere",75->"set bounties",100->"edit community wiki",100->(c+"chat rooms"),125->"vote down",150->(c+"tags"),200->("retag"+q),250->"view close votes",500->"cast close and reopen votes",750->"established user",1000->("edit"+q+" and answers"),1000->(c+"gallery chat rooms"),1250->(c+"tag synonyms"),1500->"approve tag wiki edits",2000->"access to moderator tools",3500->("protect"+q),4000->"trusted user")
d.filter(_._1<=r).toList.sortBy(_._1).map(v=>println((v._1)+" "+v._2))}

Rewrote from scratch, nearly. If I have to calculate the data in, it is cheaper (while ugly) to include the data directly.
First approach, reading event prices and privilege tab from files:
reading data from file: 405
object R extends App{import io.Source._
import java.util._
def m(n:String)={fromFile(n).getLines.toList.map{l=>val s=new Scanner(l);(s.next(),s.nextLine())}}
val e=m("e").map(a=>(a._2.trim->a._1.replaceAll("\\+","").toInt)).toMap
val p=m("p").map(b=>(b._1.toInt,b._2))
var(r,t)=(0,"")
for(t<-stdin.getLines)r+=e(t)
println(r+" reputation")
p.filter(_._1<=r).toList.sortBy(_._1).map(v=>println(v._1+v._2))}

You seem to be accessing a file, which needs to be included in the length of the program.

@PhiNotPi: Well - I understand that we have to stick to the same rules. I only had started my solution before I read the comment in lone-sharks post. Now I need some time to say goodbye to the number 462 at the top and hello to 1322.

@PhiNotPi: I don't think you're right, while being nice to me. Most of the other answers where given in good faith with the more expensive approach.

@PhiNotPi: It might be a good idea to use the sandbox on meta to get help ironing out issues like these before posting new challenges to the main site.

 J (704)
The program consists of four parts:

the following decoder script (277 bytes)
b=:,@#:@(a.i.fread)
s=:(15+6*#.@(3{.12&}.))({.;$:^:(40<#)@}.)]
r=:3 :'(15-~#.12{.y);;:^:_1[(#._6>\15}.y){u:@(96&+)&.>0 cut#._5>\b''w'''&.>@s@b
f=:3 :'>>{.&.>e#~;((<y)=}.)&.>e=:r''e'''
echo' reputation',~":R=:+/;f&.>LF cut 1!:1[3
echo>((":@>@{.),' ',>@{:)&.>p#~R>>>{.&.>p=:r'p'

a binary words file, called w, also 277 bytes (download here).
The file format is as follows: each word is encoded as a group of five-bit "bytes". Each group of five bits can have a value from 1 to 27 representing letters, or 0 being the separator. Every unique word in the description of the events and privileges is stored here.
a binary events file, called e, which is 54 bytes (download here).
Each event consists of a 12-byte reputation and one or more 6-byte words. For example, accept answer is encoded as follows:
 rep+15       Nwords  word1    word2
 000000010001 010     000110   011101
 17           2       6        29     <- these are indices in "w"
                      "accept" "answer"

a binary privileges file, called p, which is 96 bytes (download here).
The file format is the same as e, e.g. access to moderator tools is encoded as follows:
rep+15       Nwords word1    word2  word3       word4
011111011111 100    011010   011011 100000      010000
2015         4      26       27     32          16
                    "access" "to"   "moderator" "tools"

Java (1470 chars)

Note: It's a modification of Aman ZeeK Verma's answer but since my edit wasn't accepted and my answer is significantly shorter than his, I'm posting it here.
Readable Version:
import java.util.*;

public class A {

    static List m = new ArrayList();
    static String c = "create", p = "posts", w = "wiki", e = "edit", v = "vote", t = "tag", q = "questions";

    static void g(String a) {
        m.add(a);
    }

    public static void main(String a[]) {
        g("1 " + c + " " + p);
        g("5 participate in meta");
        g("10 remove new user restrictions");
        g("10 " + c + " " + w + " " + p);
        g("15 " + v + " up");
        g("15 flag " + p);
        g("20 talk in chat");
        g("50 comment everywhere");
        g("75 set bounties");
        g("100 " + e + " community " + w);
        g("100 " + c + " chat rooms");
        g("125 " + v + " down");
        g("150 " + c + " " + t + "s");
        g("200 re" + t + " " + q);
        g("250 view close " + v + "s");
        g("500 cast close and reopen " + v + "s");
        g("750 established user");
        g("1000 " + e + "s " + q + " and answers");
        g("1000 " + c + " gallery chat rooms");
        g("1250 " + c + " " + t + " synonyms");
        g("1500 approve " + t + " " + w + " " + e + "s");
        g("2000 access to moderator tools");
        g("3500 protect " + q);
        g("4000 trusted user");
        Scanner s = new Scanner(System.in);
        String i = s.nextLine();
        int r = 0;
        int b;
        while (!i.equals("")) {
            b = r(i);
            if (b == 1740) {
                r -= 15;
            }
            if (b == 1690) {
                r -= 10;
            }
            if (b == 1922) {
                r -= 5;
            }
            if (b == 1674 || b == 1906 || b == 1539) {
                r -= 2;
            }
            if (b == 1574) {
                r -= 1;
            }
            if (b == 1219 || b == 1801) {
                r += 1;
            }
            if (b == 1312 || b == 2133 || b == 1901) {
                r += 2;
            }
            if (b == 1695) {
                r += 5;
            }
            if (b == 1463) {
                r += 10;
            }
            if (b == 1513) {
                r += 15;
            }
            if (b == 1764) {
                r += 100;
            }
            i = s.nextLine();
        }
        System.out.println(r + " reputation");
        for (Object o : m) {
            if (c(o, r)) {
                System.out.println((String) o);
            }
        }
    }

    static boolean c(Object q, int r) {
        return Integer.parseInt(new StringTokenizer((String) q).nextToken()) <= r;
    }

    static int r(String i) {
        int r = 0;
        for (int k = 0; k < i.length();) {
            r += i.charAt(k++);
        }
        return r;
    }
}

Minified Version:
import java.util.*;public class A{static List m=new ArrayList();static String c="create",p="posts",w="wiki",e="edit",v="vote",t="tag",q="questions";static void g(String a){m.add(a);}public static void main(String a[]){g("1 "+c+" "+p);g("5 participate in meta");g("10 remove new user restrictions");g("10 "+c+" "+w+" "+p);g("15 "+v+" up");g("15 flag "+p);g("20 talk in chat");g("50 comment everywhere");g("75 set bounties");g("100 "+e+" community "+w);g("100 "+c+" chat rooms");g("125 "+v+" down");g("150 "+c+" "+t+"s");g("200 re"+t+" "+q);g("250 view close "+v+"s");g("500 cast close and reopen "+v+"s");g("750 established user");g("1000 "+e+"s "+q+" and answers");g("1000 "+c+" gallery chat rooms");g("1250 "+c+" "+t+" synonyms");g("1500 approve "+t+" "+w+" "+e+"s");g("2000 access to moderator tools");g("3500 protect "+q);g("4000 trusted user");Scanner s=new Scanner(System.in);String i=s.nextLine();int r=0;int b;while(!i.equals("")){b=r(i);if(b==1740)r-=15;if(b==1690)r-=10;if(b==1922)r-=5;if(b==1674||b==1906||b==1539)r-=2;if(b==1574)r-=1;if(b==1219||b==1801)r+=1;if(b==1312||b==2133||b==1901)r+=2;if(b==1695)r+=5;if(b==1463)r+=10;if(b==1513)r+=15;if(b==1764)r+=100;i=s.nextLine();}System.out.println(r+" reputation");for(Object o:m)if(c(o,r))System.out.println((String)o);}static boolean c(Object q,int r){return Integer.parseInt(new StringTokenizer((String)q).nextToken())<=r;}static int r(String i){int r=0;for(int k=0;k<i.length();)r+=i.charAt(k++);return r;}}

PHP: 676 chars
It won't win any prizes but gosh darn it I just can't figure out how to make this any smaller, so I'll just post it:
<?php
while($l=fgets(STDIN))foreach(@[j=>1,bo=>100,pt=>2,pte=>13,'r un?u?p'=>5,up=>5,wn=>-2,'e '=>1]as$k=>$v)@$r+=$v*ereg($k,$l)*(ereg(un,$l)?-1:1);$p=@preg_replace;foreach(split('
',$p('/[A-Z]/e','" ".$p("/.*?$0|[A-Z].*/","",@AaCcreateEeditGtagHchatIinLcloseMcommPpostsQquestionsRroomsTtUuserVvoteWwikiZre)',$r."Zputation
1CP
5 participateI meta
10Zmove newUZstrictions
10CWP
15V up
15 flagP
20TalkIH
50Ment everywhere
75 set bounties
100EMunityW
100CHR
125V down
150CGs
200ZtagQ
250 viewLVs
500 castLAndZopenVs
750 establishedU
1000EQAndAnswers
1000C galleryHR
1250CG synonyms
1500ApproveGWEs
2000AccessTo moderatorTools
3500 protectQ
4000TrustedU"))as$i)$r>=$i&&print"$i
";

Since the part that calcs the rep is very hard to read, here it is with extra formatting. It abuses undefined constants and uses @ to shut them up:
while($l=fgets(STDIN))
foreach(@[
        j=>1, // join website
        bo=>100, // association bonus
        pt=>2, // (un)?accept answer|answer (un)?accepted
        pte=>13, // answer (un)?accepted
        'r un?u?p'=>5, // answer (un)?upvoted
        up=>5, // (answer|question) (un)?upvoted
        wn=>-2, // (answer|question) (un)?downvoted|(un)?downvote answer
        'e '=>1 // (un)?downvote answer
        ]as$k=>$v)
    @$r+=$v*ereg($k,$l)*(ereg(un,$l)?-1:1);

You don't have to ignore warnings. It's safe to assume that PHP won't return errors or any sort.

@xfix Well it's giving me a heap of warnings so I'll bribe it with the 4 bytes to keep it quiet.

APL (549)
This one packs the data in Unicode characters.
P
D←{,⍉(20/2)⊤⎕UCS⍵}
M←{×⍴⍵:(2⊥⍺↑⍵),⍺∇⍺↓⍵⋄⍬}
Z←{15<⍴⍵:(⊂(15-⍨2⊥12↑⍵),' ',.,w[6M 15↓r↑⍵]),∇⍵↓⍨r←15+6×2⊥3↑12↓⍵⋄⍬}
w←⎕UCS¨96+1↓¨w⊂⍨0=w←5M D'崫퀖䢴鰒ᒉ৮멷ᛅ칯䉏⧩ᒉ鰕킠ؐ倬'
⎕←'reputation',⍨r←+/{⊃⊃e/⍨⍵∘{⍺≡⊃1↓⍵}¨e←Z D'Oڧ詻礽'}¨{×⍴⍵:(⊂' ',⍵),∇⍞⋄⍬}⍞
⎕←↑↑{⍵,⍨⍕⍺}/¨p/⍨r≥⊃¨p←Z D'၌ᦚ㋘爁㲦节殃䇍'

"If you use Unicode, byte count should use UTF-8." This is 1064 bytes.

Perl, 856 849 characters
$_="reputaT,A unPed,-15,A unU,-10,Q unU,-5,A DVd,-2,Q DVd,-2,unP A,-2,DV A,-1,join website,1,unDV A,1,P A,2,Q unDVd,2,A unDVd,2,Q U,5,A U,10,A Ped,15,associaT bonus,100,1,C Ps,5,participate in meta,10,remove new R restricTs,10,C wiki Ps,15,V up,15,flag Ps,20,talk in H,50,comment everywhere,75,set bounties,100,edit community wiki,100,C H rooms,125,V D,150,C tags,200,retag Qs,250,view close Vs,500,cast close and reopen Vs,750,established R,1000,edit Qs and As,1000,C gallery H rooms,1250,C tag synonyms,1500,approve tag wiki edits,2000,access to moderator tools,3500,protect Qs,4000,trusted R";$s="UupVd;Paccept;Aanswer;QquesT;Ccreate;Vvote;Ddown;Ttion;Opost;Hchat;Ruser;";$s=~s,(.)(.+?);,s/$1/$2/g;,g;eval $s;@D=split/,/;%R=@D[1..32];@P=@D[33..80];while(<>){chomp;$r+=$R{$_}}print("$r $D[0]\n");for(0..23){print"@P[$_*2,$_*2+1]\n"if$r>=$P[$_*2]}

just adding linebreaks after some semicolons for readability ;) :
$_="reputaT,A unPed,-15,A unU,-10,Q unU,-5,A DVd,-2,Q DVd,-2,unP A,-2,DV A,-1,join website,1,unDV A,1,P A,2,Q unDVd,2,A unDVd,2,Q U,5,A U,10,A Ped,15,associaT bonus,100,1,C Ps,5,participate in meta,10,remove new R restricTs,10,C wiki Ps,15,V up,15,flag Ps,20,talk in H,50,comment everywhere,75,set bounties,100,edit community wiki,100,C H rooms,125,V D,150,C tags,200,retag Qs,250,view close Vs,500,cast close and reopen Vs,750,established R,1000,edit Qs and As,1000,C gallery H rooms,1250,C tag synonyms,1500,approve tag wiki edits,2000,access to moderator tools,3500,protect Qs,4000,trusted R";
$s="UupVd;Paccept;Aanswer;QquesT;Ccreate;Vvote;Ddown;Ttion;Opost;Hchat;Ruser;";
$s=~s,(.)(.+?);,s/$1/$2/g;,g;eval $s;
@D=split/,/;%R=@D[1..32];@P=@D[33..80];
while(<>){chomp;$r+=$R{$_}}print("$r $D[0]\n");
for(0..23){print"@P[$_*2,$_*2+1]\n"if$r>=$P[$_*2]}

Python 3.x (801 chars)
Best I can do so far, just need to work out a better encoding than base64 (hint hint: can somebody assist?).
import base64,zlib
exec(zlib.decompress(base64.b64decode(b'eJxtU93O2jAMve9T+K7tCJ+ArZqExpMgLkJrICNNsvxQoel799kplI7toqLYPsfHx27hxVkoIYXbrcT+IJRxKVa1+F0m09nB3GxEkCYM6MvtWpSybdHFKbKhSH6FMYEdVTWi/GmVgQGPQUUccSHYVsmorIGjNSlQdLUS5a+EIQeT41YEJ3Qyb22Wm3nlJKybC5gFufwf8cv1VJrM1G25not445jKX8MtebqZlBdRM6v/r8CpdL36JH899vaGYHCAFCjtidOrlnmzOYRzznNJlGcY1FUBdipyrmHnWo8yjslwN9bce05tGkoFjGRyMlEhxb6TMkZCa/s+GRXvme2xgOxRcuPaqF/ENsJzQEJ/nTc7S63R36G9yAje2n5cIxcQN5oIeKP8cEFPa2/+UjkKp4gMJEXbwKvpaGzr0ADLCAx5YfLIzob4sCNKfQU6K25OvrJ2ReaNVA98Hj8PO42Qu4wreKkdOzzJx7MOAaKF3nboZbSe/ljNlBlBZPKoVbhgl9fFtrImn0KcQt/m5G8ekbnSR9Uqx0kao8co87V75B3OLN9w9UlT8CmweeyJ7yov+bM4kULNPOojOK1iVZZlQU+9LUCdQNMP+MVO7vWhcF6ZWHluRV93/gjLOjMoZnAjxO3V4cfOM/D8QbeHpqvoJCuO14sSyoWqH1RfgvU0dnUWV7zvtOyPnQS5Bc7Jpx4o6/3qUNcioNs91RV/ACHUeCw=')).decode())

Python 3.8 (pre-release), 714 bytes
r=0
L=' questions'
C=',create '
K=f'j,nv,n u,r u,ss,e ,t ,pte,reputation{C}posts,participate in meta,remove new user restrictions{C}wiki posts,vote up,flag posts,talk in chat,comment everywhere,set bounties,edit community wiki{C}chat rooms,vote down{C}tags,retag{L},view close votes,cast close and reopen votes,established user,edit{L} and answers{C}gallery chat rooms{C}tag synonyms,approve tag wiki edits,access to moderator tools,protect{L},trusted user'.split(',')
while 1:
 i=input()
 if not i:break
 r+=[1,-2,5,10,100,-1,2,15][[a in i for a in K].index(1)]*(1-2*('un'in i))
for R,j in zip([r,1,5,10,10,15,15,20,50,75,100,100,125,150,200,250,500,750,1e3,1e3,1250,1400,2e3,3500,4e3],K[8:]):
 if R<=r:print(R,j)

Try it online!
Yay, I'm 1 byte below the best answer!
Uses the restricted input format (input through STDIN, output through STDOUT).
Surprisingly, switching to a lambda only saves thirteen bytes.


text:
Can you Meta Quine?
Similar to other quine puzzles (more specifically, this one), write a program that produces the source for itself.
Here's the new twist: The code produced should NOT be identical to the source. Rather, it should output a different program that will create the first.
The challenge linked to above achieved that by jumping between two languages. I'm thinking this one would be done in just one language, but the two (or more) versions of the source should be significantly different (see rules below). With this constraint, single character answers would be disallowed, thus requiring a little more thought be put into a final submission.

RULES

Your code must be produced in just one language. (Multiple submissions, one for each language is perfectly acceptable.)
Your different code versions must be syntactically distinct. In other words, if you were to draw out an abstract syntax tree for your code, there should be at least one node different.

Supplying an AST will not be necessary, but if you feel inclined to provide one for each of your programs, it would help in judging.

You may produce as many iterations as you wish, as long as they all remain syntactically distinct. (More will help your score, see below.)

SCORING
Your final score will be the mean length of all your programs, divided by the number of programs.
Example 1:

A (source for B) = 50 characters
  B (source for A) = 75 characters
  Final Score = 31.25

Example 2:

A (source for B) = 50 characters
  B (source for C) = 75 characters
  C (source for A) = 100 characters
  Final Score = 25

I meta quine once.

@mellamokb har har ;-)

This is actually just a more general version of this quine challenge, and the answers given there will win here, too.

@leftaroundabout, the requirement for syntactic differences invalidates a 'rotating quine', so this is not more general.

@leftaroundabout I was thinking this current form was enough, but if there is still disagreement about boothby's point, I do have an extra alternative constraints I can add.

Never meta quine I didn't like.

Python, 0 (limit of (68+3 n )/(16n))
If two abstract syntax trees are different if they have different constants,
r='r=%r;n=(0x%XL+1)%%0x10...0L;print r%%(r,n)';n=(0xF...FL+1)%0x10...0L;print r%(r,n)

there are 16n programs of length at most 68+3n, giving asymptotic score of 0.
If you want programs with variable structure, we can implement a binary adder on n bits.  Here, there are 2n programs of length O( n2).  Goes in a cycle due to dropped carry bit.
s="""
print 's='+'"'+'"'+'"'+s+'"'+'"'+'"'
n=lambda m:reduce(lambda (s,c),y:(s+(c^y,),c&y),m,((),1))[0]
print s[:112]
t=n(t)
print "t=(%s,)+(0,)*%s"%(t[0],len(t)-1)
for i in range(len(t)-1):
    print i*' '+'for i in range(2):'
    print ' '+i*' '+['pass','t=n(t)'][t[i+1]]
print s[113:-1]
"""

print 's='+'"'+'"'+'"'+s+'"'+'"'+'"'
n=lambda m:reduce(lambda (s,c),y:(s+(c^y,),c&y),m,((),1))[0]
print s[:112]
t=(0,)+(0,)*10
for i in range(2):
 t=n(t)
 for i in range(2):
  t=n(t)
  for i in range(2):
   t=n(t)
   for i in range(2):
    t=n(t)
    for i in range(2):
     pass
     for i in range(2):
      t=n(t)
      for i in range(2):
       pass
       for i in range(2):
        pass
        for i in range(2):
         pass
         for i in range(2):
          t=n(t)
t=n(t)
print "t=(%s,)+(0,)*%s"%(t[0],len(t)-1)
for i in range(len(t)-1):
    print i*' '+'for i in range(2):'
    print ' '+i*' '+['pass','t=n(t)'][t[i+1]]
print s[113:-1]

Might I be confused? It looks like the output is identical to the source (not the objective of this challenge)?

Look in the nested block.  pass will change to t=n(t) and back, in all 2^n combinations.

I do see that now. You confused me with all the repetition!

for some reason, I like very long golf solutions with tiny scores.

Wow, you completely owned that! Very nice.

C++, score of 0.734194
The following source code prints a meta quine of order 999 to the console (explanation below):
#define X 1*(1+1)
#include<iostream>
#include<vector>
#define Q(S)auto q=#S;S
Q( \
  main() \
  { \
      using namespace std; \
      cout<<"#define X 1"; \
      int x=X==2?1000:X-1; \
      vector<int> factors; \
      for ( int p = 2; p <= x; ++p) \
      { \
        while ( x % p == 0 ) \
        { \
          factors.push_back( p ); \
          x /= p; \
        } \
      } \
      for ( int factor : factors ) \
      { \
        cout<<"*(1"; \
        for ( int i=1;i<factor;++i) \
          cout<<"+1"; \
        cout<<")"; \
      } \
      cout<<"\n#include<iostream>\n#include<vector>\n#define Q(S)auto q=#S;S\nQ("<<q<<")"; \
  })

The only line that changes is the first line. The value of X will be 1000, 999, 998, ..., 3, 2 and then it will start again. However, in order to get different syntax trees every time, X is represented in terms of its prime factorization, where every prime is written as a sum of 1s. The ASTs are different, because the prime factorization of integers is different for every value.
The program will print itself, except that the first line is changed and the backslashes, line breaks and indentations that are within Q(...) will be removed.
The following program calculates the score of my answer:
#include <iostream>

const int n = 1000;

int getProgramLength( int n )
{
  int sum = 442;
  for ( int p = 2; p*p <= n; ++p )
  {
    while ( n % p == 0 )
    {
      sum += 2 * ( 1 + p );
      n /= p;
    }
  }
  if ( n > 1 )
    sum += 2 * ( 1 + n );
  return sum;
}

int main()
{
  int sum = 0;
  for ( int i = 2; i <= n; ++i )
    sum += getProgramLength( i );
  std::cout << (double)sum/(n-1)/(n-1) << '\n';
}

It printed 0.734194 to the console. Obviously, 1000 can be replaced by larger integers and the score will approach 0 as its limit. The mathematical proof involves Riemann's Zeta function is somewhat convoluted. I leave it as an exercise to the reader. ;)

Perl, score of 110.25
I have to admit, I'm not very good with quines. I'm 100% certain that there is room for improvement. The solution is based off of the same principle of the Element solution below.
The first program is 264 characters.
$s='$a=chr(39);print"\$s=$a$s$a;";$s=reverse$s;for(1..87){chop$s}$s=reverse$s;print$s;$f++;if($f==0){$a=chr(39);print"\$s=$a$s$a;$s"}';$a=chr(39);print"\$s=$a$s$a;";$s=reverse$s;for(1..87){chop$s}$s=reverse$s;print$s;$f++;if($f==0){$a=chr(39);print"\$s=$a$s$a;$s"}

The second program is 177 characters.
$s='$a=chr(39);print"\$s=$a$s$a;";$s=reverse$s;for(1..87){chop$s}$s=reverse$s;print$s;$f++;if($f==0){$a=chr(39);print"\$s=$a$s$a;$s"}';if($f==0){$a=chr(39);print"\$s=$a$s$a;$s"}

I'm working on the AST for this entry (and the Element entry).

Element, score of 47.25
The first program is 105 characters.
\ \3\:\$\'\[\\\\\`\(\`\]\#\2\1\'\[\(\#\]\`\ \3\:\$\'\[\\\\\`\(\`\]\#\` 3:$'[\\`(`]#21'[(#]` 3:$'[\\`(`]#`

The second program is 84 characters.
\ \3\:\$\'\[\\\\\`\(\`\]\#\2\1\'\[\(\#\]\`\ \3\:\$\'\[\\\\\`\(\`\]\#\` 3:$'[\\`(`]#`

I'm sure that there is a lot of room for improvement.
In the first program there is one string (in which every character is escaped, despite a lot of redundancy) followed by executable parts A and B. Part A does several things: prints the string and escapes out of every character,  prints the last half of the string (which is the source for part B), and then prevents the part B that follows it from doing anything.
The second program is the same string followed by part B. Part B is based off of a simple quine; it prints a string preceded by an escaped version of it. This means it prints the string, and both parts A and B.

I think this definitively, beyond any doubt, proves the validity of Element as a programming language. It is so easy to use that I, so inexperienced that I have only managed to write one complete interpreter for Element, have been able to answer this question before any other person on this entire planet of 7,000,000,000 people. Element's "one character, one function, all the time"  paradigm  means that  all code is completely unambiguous. The language is versatile: except for []{}, any command can be placed anywhere in the entire program without causing a syntax error. It is perfect.

A bit biased, are we? ;-)

VBA: (251+216)/2/2 = 116.75
251
Sub a()
r=vbCrLf:c="If b.Lines(4, 4) = c Then"&r &"b.InsertLines 8, d"&r &"b.DeleteLines 4, 4"&r &"End If":d="b.InsertLines 6, c"&r &"b.DeleteLines 4, 2"
Set b=Modules("Q")
If b.Lines(4, 4) = c Then
b.InsertLines 8, d
b.DeleteLines 4, 4
End If
End Sub

216
Sub a()
r=vbCrLf:c="If b.Lines(4, 4) = c Then"&r &"b.InsertLines 8, d"&r &"b.DeleteLines 4, 4"&r &"End If":d="b.InsertLines 6, c"&r &"b.DeleteLines 4, 2"
Set b=Modules("Q")
b.InsertLines 6,c
b.DeleteLines 4,2
End Sub

This is run in MSAccess to make use of the Module object. The module is named "Q" for golfing. The difference in syntax comes from the If ... Then missing from the shorter version.

you can most likely get away with changing vbCrLF to vbCr

JavaScript, 84.5 64 61
Two programs, both length 169 128 122.
(function c(){alert(/*
2/*/1/**/);return ('('+c+')()').replace(/\/([/\*])/,function(m,a){return a=='*'?'/\/':'/\*'});
})()

Before I golfed it, for your viewing pleasure:
(function c() {
    var r = /\/([/\*])/;
    var f = function(m, a) { return a === '*' ? '/\/' : '/\*' };
    var p = '(' + c + ')();';
    p = p.replace(r, f);
    /* This is just a comment!
    console.log('Quine, part two!'); /*/
    console.log('Quine, part one!'); /**/
    return p;
})();

Returns the new program and outputs the current part! I could probably make it shorter without the function regex, but... I don't want to.

No, they're syntatically distinct. Once you add the newlines, that is.

J - (24+30)/2 / 2 = 13.5 pts
Note that strings in J are not the backslash-escaped, but quote-escaped à la Pascal: 'I can''t breathe!'.
30$(,5#{.)'''30$(,5#{.)'         NB. program 1, 24 char
'30$(,5#{.)''''''30$(,5#{.)'''   NB. program 2, 30 char

Program 1 has AST noun verb hook noun and program 2 has AST noun. Program 2 is a quoted version of program 1, which will just return program 1 when run, so this method can't be extended to three copies that easily :P
Program 1 operates by taking a copy of the code portion of the source, with a quote appended at the front, and adding five of those quotes to the end ((,5#{.)). Then, it cyclically takes 30 characters from this 16-character string, which gives exactly Program 2 as a result.

source: Stack Exchange

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

sort: votes


text:
Code Golf: What is the spaceship's fate? [ASCII art version]
Background
In a galaxy (and possibly a universe) far, far away... there was a spaceship and a bunch of planets. A malfunction on board caused the spaceship to run out of fuel. It is now moving at a dangerously slow speed near a cluster of planets, from which it must escape! What will be the crew's fate?
The Challenge
You are the lead programmer on the U.S.S. StackExchange. As such, you desire to write a simulator that will reveal whether or not you are doomed to crash land onto a planet, will escape the planetary system, or will be stuck in orbit forever.
The explosion on your spaceship, however, means that there was very limited computational resources. Your program must be as small as possible. Also, this means that the only possible way of inputting simulations to run is through ASCII art.
The Simulation
In this quadrant of the multiverse, the laws of physics are slightly altered in order to accommodate ASCII art. This means that the cosmos is divided up into cells. Movement will be described in units of cells, and time will be in units of time steps.
The ship itself has momentum. If the ship moved +2 cells on the x axis and -1 cell on the y axis (shorthanded as (2,-1)) in the previous time step, and there is no gravitational field, then the ship will move with the exact same velocity on the next time step.
There will be several planets, all of which exert a gravitational field on the eight cells immediately surrounding it, which will effect the ship's velocity and will pull the ship closer to the planet. Being just "north" of a planet will result in a field pulling the ship one cell to the "south" with a force of (-1,0). Being just "northeast" of a planet will result in a force pulling the ship one cell to the "south" and one unit to the "west" with a force of (-1,-1).
The gravitational fields add a vector to the ship's momentum as it is leaving the cell with the gravity. If a ship just previously moved (2,-1) cells and is now in a gravitational field of (-1,1), then in this next time step it will move (1,0) cells. If the ship is in close proximity to multiple planets, then there will be multiple vectors to add.
Input
On STDIN, you will receive an ASCII art representation of the planetary system that will show the coordinates of the planets and your ship's current velocity. There will be several planets in the form of @ signs, while there will be one spaceship in the form of a v^<> sign. The choice of symbol for the ship indicates the current velocity of the ship (before gravity has been added). For example, a < means a velocity of one cell to the west, while a ^ means a velocity of one cell to the north. All empty space will consist of periods, which pad every line to be the same width. A blank line represents the end of input. Here is an example of an input:
.................
...@.@........v..
......@..@..@@...
..@..............
.......@..@......
.................

Output
Output will be a single word on STDOUT, which will tell whether the ship will escape gravity, will crash land into a planet, or will orbit forever.
Escaping from gravity is defined as the ship moving off of the map. If the ship escapes, then your program must print the word "escape".
Crash landing is when a ship passes directly over a planet or ends up in the same cell during a time step. Note that it is not enough to simply calculate where the ship is every time step. A ship moving at a velocity of (5,5) will crash into a planet located at (1,1) even though straightforward calculation will mean that it will never visit that cell. A ship with a velocity of (5,6) will not crash land into the planet, however. If your spaceship crash lands, then your program must print the word "crash".
Orbiting may be the most difficult to detect. Orbiting occurs whenever the spaceship visits the same cell twiceand with the same velocity. If the ship orbits, then you should print the word "orbit".
Here is the output for the above example:
escape

Explanation
Here is a map showing where the spaceship traveled in each time step in the above example:
   ^
.................
...@.@........v..
....^.@..@..@@...
..@..<.<<<.<.v...
.......@..@......
.................

It went south, turned to the west, travelled down a corridor, turned to the north, and narrowly escaped between to planets with a high velocity, all becuase of gravity.

More cases for examination
...
^@.
...
orbit
...........
.>@.@......
.@......@..
....@......
crash (it crashes into the easternmost planet)
...
.@.
.v.
crash (momentum can't overcome gravity)
........
..@.....
..<.....
...@....
........
orbit (it gets trapped in a gravity well between two planets)

Rules, Regulations, and Notes
This is code golf. Standard code golf rules apply. Your programs must be written in printable ASCII. You aren't allowed to access any sort of external database.
End Transmission

There appears to be a typo in the line just above the INPUT section... I assume you mean planet? :-)

Actually, that whole partial paragraph needed to be deleted, the information is repeated under the output section.

I'd like this better with slightly less altered physics... this site could do with more problems that also involve a little nice expensive floating-point arithmetic.

@leftaroundabout That may be my next challenge.

How close to a planet does it need to be to crash into it?

I crashes if the path takes it directly over a planet. This means that either it lands on the same cell as a planet, or the line of travel between two locations takes it directly through the point.

C# 991 984
struct P{public P(int x,int y){X=x;Y=y;}public int X,Y;}
class O:Exception{}
class C:O{}
List<P>p=new List<P>();
List<string>h=new List<string>();
P r,v,u;
void S(){
var i=0;
for(var l=Console.ReadLine();l!="";l=Console.ReadLine())
{u.X=l.Select((c,j)=>
{if(c=='@')p.Add(new P(j,i));else if(c!='.')
{r=new P(j,i);v=(c=='v'?new P(0,1):c=='<'?new P(-1,0):c=='^'?new P(0,-1):new P(1,0));}
return u;}).Count();i++;}
u.Y=i;
var x=new Action<string>(Console.WriteLine);
try{
while(true){
p.ForEach(q=>{var a=q.X-r.X;var b=q.Y-r.Y;
if(a<2&&a>-2&&b<2&&b>-2){v.X+=a;v.Y+=b;}});
var c=string.Join(".",r.X,r.Y,v.X,v.Y);
if(h.Contains(c))throw new O();
h.Add(c);
var z=new P(r.X,r.Y);var k=new[]{v.X,v.Y};var m=k.Min();var M=k.Max();
for(var j=1;j<=M;j++)
if((j*m)%M==0){
if(p.Contains(new P(z.X+(v.X==M?j:j*m/M),z.Y+(v.Y==M?j:j*m/M))))throw new C();}
r.X+=v.X;r.Y+=v.Y;
if(r.X<0||r.X>=u.X||r.Y<0||r.Y>=u.Y)throw new Exception();}}
catch(C){x("crush");}
catch(O){x("orbit");}
catch{x("escape");}}

The ungolfed (and slightly refactored) version is available at http://pastebin.com/yAKYvwQf
Running version: https://compilify.net/1n9
This has been slightly modified to be run on complify:

no implicit array creation - ex: new[]{1,2}
uses return <string> instead of Console.WriteLine, because that's how compilify.net works

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


text:
Score a Cribbage Hand
This challenge is to score a Cribbage hand.  If you don't play Cribbage, you've got some learning to do.  We play with a standard poker deck, and a hand consists of four cards plus the "up card".  There are two types of hand: normal, and a 'crib hand'.
Cards come in the format vs where v is one of: A23456789TJQK (T for ten) and s is one of SCDH.  A hand will be given in the form (for example)
AS 2D 3H JS | 4S

where 4S is the up card.  A crib hand will have the format
JD 3C 4H 5H | 5S !

Face cards have a value of 10, and the ace has a value of 1.  Scoring is performed as follows.

Fifteens: for each subset of five cards whose sum is 15, add two points.
Pairs: for each pair of cards with the same rank (not value), add two points.
Runs: for each maximal run of consecutive cards of length longer than 2, add the length of the run in points.
Flush: if all five cards are the same suit, add five points.  Otherwise, if all but the up card are the same suit, add four points.  If this is a crib hand, the four-point variant is not counted.
Nobs: if there is a jack in hand with the same suit of the up card, add one point.

Notes:

Triples and fours of a kind are not special -- there are three pairs in a triple, so a triple is worth 6 points.
Runs can overlap.  For example, AS AH 2D 3C | 2C (a double double run) has four runs of length 3 and two pair, so is worth 3+3+3+3+2+2 = 16 points.
Only maximal runs are counted, so KS QD JD TC | 9S is worth 5 points, since it is a run of 5.  The sub-runs are not counted.

House Rule:
It's impossible to score 19 points in a hand.  Instead of zero, report a score of 19.
Examples:
5S 5H 5D JS | KS
21

AS 2D 3H JS | 4S !
9

JD 3C 4H 5H | 5S
12

9S 8S 7S 6S | 5H !
9

9S 8S 7S 6S | 5H
13

8D 7D 6D 5D | 4D !
14

8D 7D 6D 5D | 4D
14

AD KD 3C QD | 6D
19

This is code golf.  Shortest solution wins.

"fifteen two, fifteen four, ..." Aye, yai, yai, but it's been a while.

@dmckee, yes, I was very nice in my requirements for scoring.  I thought about putting up a full description of the patter... "fifteen two, fifteen four, and a pair for six; peg them sticks".  But then, the problem description would be 30 pages long.

3+3+3+3+2 = 16? I think you're missing another +2.

And are the second and last examples meant to be 9 and 1? I think the last rule should apply to them, but I'm not sure (never played cribbage before).

@grc yup, I missed the nobs on those.  This is the only game I know in which scoring is the hardest part.

in case this helps someone, to calculate the num of pairs with the total num of X card is: (len*(len-1))/2 I struggled to figure this out

Big fan of cribbage, but I've got a hard enough time scoring the hands myself sometimes - let alone thinking up how I'll teach a computer to do it. This is going on my to-do list, but not expecting anything soon. :-(

Double-check your math on the double-double run of 3 - should be 16 points. It looks like you had the total right, but the equation wrong, before you edited for @grc's comment.

@Iszi My greatest fear: AI advances to the point that computers refuse to add for me.

Explain why I can't score 19. I play cribbage sometimes and since 22 is definitely possible, why not 19?

@StackMeterPlus It's just an accident of how the scoring works. Scores of 19, 25, 26, and 27 are all impossible. (And of course, anything above 29.) There's no real proof of this, short of listing the entire set of cribbage hands. That said, note that the only odd scores are single runs, triple-runs, and hisnobs. If you look at the 18-point hands, you'll see that either they can't be modified to add hisnobs to their score, either because they can't have a Jack (e.g. 3-3-6-6-6), or else they are already using hisnobs (e.g. 10-J-Q-5-5, which would be 17 points without hisnobs).

GolfScript, 187 178 174 characters
:c"J"c{"SCDH"?)},1/:s-1=+/,([s)-!5*s);)-!4*c"!"?)!*]$-1=+0.14,{c{"A23456789TJQK"?)}%{},:v\{=}+,,.{@*\)}{;.2>**+1 0}if}/;;5-v{{=+}+v\/}/[0]v{.9>{;10}*{1$+}+%}/{15=},,2*+.!19*+

Since I never played cribbage I don't know any fancy scoring tricks. Therefore I thought the only way to compete (at least a little bit) is using a golf language. The code is pretty plain GolfScript, the test cases can be found here.
The code in a more readable fashion (reformatted and ungolfed a little):
# Save cards to <c>
:c;

# Is it a non-crib hand? <r>
c"!"?)!:r;

# Values go to <v>
c{"A23456789TJQK"?)}%{},:v;

# Suits go to <s>
c{"SCDH"?)},1/:s;

# Print score for Fifteens
[0]v{.9>{;10}*{1$+}+%}/{15=},,2* .p

# Print score for Pairs
-5v{{=+}+v\/}/ .p

# Print score for Runs
0..14,{v\{=}+,,.{*\)\}{;\.2>**+0 1}if}/;; .p

# Print score for Flush
[s)-!5*s);)-!4*r*]$-1= .p

# And finally print the score for Nobs
c"J"s-1=+/,( .p

# Sum up the sub-scores and if score is zero set to 19
++++
.!19*+

Edit: Changed logic for fifteens and flushes.

Yikes!  That's the longest GS script I've ever seen!  Bravo!

C, 364 388 chars
It's big and ugly (though not as big as it once was):
char*L="CA23456789TJQKDHS",b[20],p[15],r[5],s[5],v,i=4,t,m,q;
g(j){++p[r[i]=strchr(L,b[j])-L];s[i]=strchr(L,b[j+1])-L;}
f(j,u){u==15?v+=2:++j<5&&f(j,u,f(j,u+(r[j]>9?10:r[j])));}
main(){gets(b);for(g(14);i--;r[i]^11|s[i]^s[4]||++v)g(i*3);
for(f(i,0);++i<15;v+=q?q*q-q:t>2?t*m:0,t=q?t+1:0,m=q?m*q:1)q=p[i];
while(++t<5&&s[t]==*s);v+=t>4-!b[16]?t:0;printf("%d\n",v?v:19);}

(Line breaks were added to make it easier to read; those aren't included in the above tally.)
The problem description didn't specify if the code needed to check for invalid input, so naturally I assumed that the program was free to misbehave at will if the input, say, contained extra whitespace.
Here's the ungolfed version:
#include <stdio.h>
#include <string.h>

/* A-K correspond to values 1-13. Suit values are arbitrary.
 */
static char const *symbols="CA23456789TJQKDHS";

/* Used as both an input buffer and to bucket cards by rank.
 */
static char buf[20];

/* The cards.
 */
static int rank[5], suit[5];

/* The cards broken down by rank.
 */
static int buckets[15];

static int score;
static int touching, matching, i;

/* Read card number i from buf at position j.
 */
static void getcard(int j)
{
    rank[i] = strchr(symbols, buf[j]) - symbols;
    suit[i] = strchr(symbols, buf[j+1]) - symbols;
    ++buckets[rank[i];
}

/* Recursively find all combinations that add up to fifteen.
 */
static void fifteens(int j, int total)
{
    for ( ; j < 5 ; ++j) {
        int subtotal = total + (rank[j] > 9 ? 10 : rank[j]);
        if (subtotal == 15)
            score += 2;
        else if (subtotal < 15)
            fifteens(j + 1, subtotal);
    }
}

int main(void)
{
    fgets(buf, sizeof buf, stdin);
    score = 0;

    /* Read cards from buf */
    for (i = 0 ; i < 4 ; ++i)
        getcard(i * 3);
    getcard(14);

    /* Score fifteens */
    fifteens(0, 0);

    /* Score any runs and/or pairs */
    touching = 0;
    matching = 1;
    for (i = 1 ; i < 15 ; ++i) {
        if (buckets[i]) {
            score += buckets[i] * (buckets[i] - 1);
            ++touching;
            matching *= buckets[i];
        } else {
            if (touching > 2)
                score += touching * matching;
            touching = 0;
            matching = 1;
        }
    }

    /* Check for flush */
    for (i = 1 ; i < 5 && suit[i] == suit[0] ; ++i) ;
    if (i >= (buf[17] == '!' ? 5 : 4))
        score += i;

    /* Check for hisnob */
    for (i = 0 ; i < 4 ; ++i)
        if (rank[i] == 11 && suit[i] == suit[4])
            ++score;

    printf("%d\n", score ? score : 19);
    return 0;
}

Since I didn't specify, feel free to shave off those 20 chars!

This is really impressive -- the question is big & ugly too!  This being code golf, segfaulting on crap input is a-ok.

Ruby 1.9, 359 356
It's far too long - almost as much as the C solution.
R='A23456789TJQK'
y=gets
f=y.scan /\w+/
o=f.map(&:chr).sort_by{|k|R.index k}
s=0
2.upto(5){|i|o.combination(i){|j|t=0
j.map{|k|t+=k==?A?1:k<?:?k.hex: 10}
(t==15||i<3&&j.uniq!)&&s+=2}}
m=n=l=1
(o+[z=?_]).map{|k|k[z]?n+=1:R[z+k]?(m*=n
l+=n=1):(l>2&&s+=l*m*n
l=n=m=1)
z=k}
x=f.take_while{|k|k[y[1]]}.size
x>(y[?!]?4:3)&&s+=x
y[?J+f[4][1]+' ']&&s+=1
p s>0?s:19

Something to begin with.. Ruby, 422 365 355 352
c=gets
a,b=c.scan(/(\w)(\w)/).transpose
f=->x{x.uniq.size<2}
s=f[b]?5:!c[/!/]&f[b[0,4]]?4:0
c[/J(.).*\1 ?!?$/]&&s+=1
s+=[5,4,3].map{|i|a.permutation(i).map{|x|'A23456789TJQK'[x*'']?i:0}.inject :+}.find{|x|x>0}||0
a.map{|x|s+=a.count(x)-1}
2.upto(5){|i|s+=2*a.map{|x|x.tr(?A,?1).sub(/\D/,'10').to_i}.combination(i).count{|x|x.inject(:+)==15}}
p s<1?19:s

Slightly ungolfed:
def t(c)
  s=0

  if c.scan(/[SDHC]/).uniq.size<2 # Flush
    s+=5
  elsif c[0..9].scan(/[SDHC]/).uniq.size<2 && c[-1]!=?! # Flush
    s+=4
  end
  s+=1 if c =~ /J(.).*(\1$|\1\s.$)/ # Nobs

  c=c.scan(/[^ \|]+/).map{|x|x[0]}[0..4]
  d = (3..5).map{|i|c.permutation(i).map{|x| 'A23456789TJQK'.include?(x*'') ? i : 0}.inject(:+)}.reverse.find{|x|x>0} || 0# Runs
  s+=d
  c.map{|x|s+=c.count(x)-1} # Pairs
  c.map!{|x|x.tr('A','1').gsub(/[JQK]/,'10').to_i}
  (2..5).map{|i|s+=2*c.combination(i).count{|x|15==x.inject(:+)}} # 15s
  s<1 ? 19 : s
end

Unit tests for golfed version:
require "test/unit"

def t(c)
c=gets
a,b=c.scan(/(\w)(\w)/).transpose
f=->x{x.uniq.size<2}
s=f[b]?5:!c[/!/]&f[b[0,4]]?4:0
c[/J(.).*\1 ?!?$/]&&s+=1
s+=[5,4,3].map{|i|a.permutation(i).map{|x|'A23456789TJQK'[x*'']?i:0}.inject :+}.find{|x|x>0}||0
a.map{|x|s+=a.count(x)-1}
2.upto(5){|i|s+=2*a.map{|x|x.tr(?A,?1).sub(/\D/,'10').to_i}.combination(i).count{|x|x.inject(:+)==15}}
p s<1?19:s
end

class Test1 < Test::Unit::TestCase
  def test_simple
    assert_equal 21, t("5S 5H 5D JS | KS")
    assert_equal 21, t("JS 5H 5D 5S | KS")
    assert_equal 12, t("JD 3C 4H 5H | 5S")
    assert_equal 13, t("9S 8S 7S 6S | 5H")
    assert_equal 14, t("8D 7D 6D 5D | 4D")
    assert_equal 19, t("AD KD 3C QD | 6D")
    assert_equal 9, t("AS 2D 3H JS | 4S !")
    assert_equal 9, t("JS 2D 3H AS | 4S !")
    assert_equal 14, t("8D 7D 6D 5D | 4D !")
    assert_equal 9, t("9S 8S 7S 6S | 5H !")
  end
end

Results:
% ruby ./crib.rb
   Run options:

# Running tests:

21
21
12
13
14
19
9
9
14
9
.

Finished tests in 0.014529s, 68.8281 tests/s, 688.2813 assertions/s.

1 tests, 10 assertions, 0 failures, 0 errors, 0 skips

Python, 629 characters
I'm only posting mine because no one else has. It's pretty long :(
g=range
i=raw_input().split()
r,u=zip(*[tuple(x)for x in i if x not in'!|'])
v=map(int,[((x,10)[x in'TJQK'],1)[x=='A']for x in r])
z=list(set(map(int,[(x,dict(zip('ATJQK',[1,10,11,12,13])).get(x))[x in'ATJQK']for x in r])))
z.sort()
z=[-1]*(5-len(z))+z
s=p=l=0
for a in g(5):
 for b in g(a+1,5):
    s+=2*(v[a]+v[b]==15)
    p+=2*(r[a]==r[b])
    if z[a:b+1]==g(z[a],z[b]+1)and b-a>1:l=max(l,b+1-a)
    for c in g(b+1,5):s+=2*(v[a]+v[b]+v[c]==15)
for d in g(5):s+=2*(sum(v)-v[d]==15)
n=len(set(u))
s+=4*(n==2 and u[-1] not in u[:4] and i[-1]!='!')+5*(n<2)+('J'+u[4]in i[:4])+2*(sum(v)==15)+p+((l*3,l*p)[p<5]or l)
print(s,19)[s<1]

Wow, that is long!  Nicely done, though.  BTW, you never need spaces before/after quotes and brackets.

Oh thanks, I forgot about that. It's slightly shorter now ;)

How about print s or 19? I think you can also use Python 3.x and shave off 3 more characters (raw_input to input, then print s or 19 to print(s or 19)).

Python 2, 606 584 bytes
Saved 22 bytes due to Jo King's golfing.
from itertools import*
s,S,C,E=sum,sorted,combinations,enumerate
def f(a):a=a.split();a.pop(4);e=a.pop(5)if a[-1]<"$"else 0;b=S("A23456789TJQK".index(i)for i,j in a);d=S(set(b));h=[j for i,j in a];z=len([s(k)for r in range(6)for k in C([[10,k+1][k<10]for k in b],r)if s(k)==15])*2+s(2for i,j in C(b,2)if i==j)+[4*(e<1),5][len(set(h))<2]*(len(set(h[:4]))<2)+(a[4][1]in[j for i,j in a[:4]if i=="J"])+s(reduce(lambda x,y:x*y,[b.count(k)for k in m])*len(m)for m in[d[s(x[:i]):s(x[:i])+j]for x in[[len(list(e))for i,e in groupby(j-i for i,j in E(d))]]for i,j in E(x)if j>2]);return z or 19

Try it online!
Slightly shorter than grc's answer, and takes a different route to get there.
Explanation:
    # import everything from "itertools" library. We only need "combinations" and "groupby".
from itertools import*
# alias functions to shorter names
s,S,C,E=sum,sorted,combinations,enumerate

# function f which takes the hand+up card+crib string as its argument
def f(a):
    # convert space-separated string into list of items.
    a=a.split()

    # remove the 4th index, which is always "|".
    a.pop(4)

    # change golfed by Jo King
    # if the final item in the list is a "!" (if it is <"$"), remove it from the list and assign it to variable "e".
    # otherwise, assign 0 to variable "e".
    # a non-empty string will evaluate to True and 0 will evaluate to False in IF checks later.
    e=a.pop(5)if a[-1]<"$"else 0

    # for each card in the list, split the identifiers into the value(i) and the suit(j).
    # return the value's index in the string "A23456789TJQK".
    # so, ["5S", "5H", "5D", "JS", "KS"] will return [4, 4, 4, 10, 12].
    # using the aliased built-in function sorted(), sort the list numerically ascending.
    b=S("A23456789TJQK".index(i)for i,j in a)

    # get the unique items in b, then sort the result numerically ascending.
    d=S(set(b))

    # for each card in the list, split the identifiers into the value(i) and the suit(j).
    # return the suits.
    h=[j for i,j in a]

        # fifteens
        # changes golfed by Jo King
        # generate pairs of (10, value + 1) for all cards (since they are zero-indexed)
        # since True and False evaluate to 1 and 0 in python, return 10 if k>=10
        # and reduce all values >10 to 10
        # get all unique combinations of cards for 5 cards, 4 cards, 3 cards, 2 cards, and 1 card
        # add the values of all unique combinations, and return any that equal 15
        # multiply the number of returned 15s by 2 for score
    z=len([s(k)for r in range(6)for k in C([[10,k+1][k<10]for k in b],r)if s(k)==15])*2
        +
        # pairs
        # using itertools.combinations, get all unique combinations of cards into groups of 2.
        # then, add 2 for each pair where both cards have an identical value.
        s(2for i,j in C(b,2)if i==j)
        +
        # flush
        # changes golfed by Jo King
        # using list indexing
        # [4 * (0 if crib else 1), 5], get item at index [0 if more than one suit in hand+up card else 1]
        #    -> 4 if not crib and not all suits same
        #    -> 5 if all cards same
        #    -> 0 otherwise
        # * (0 if more than one suit in hand else 1)
        #    -> 4 * 0 if not crib and not all suits same
        #    -> 4 * 1 if not crib and all suits same
        #    -> 5 * 1 if all cards same
        #    -> 0 otherwise
        [4*(e<1),5][len(set(h))<2]*(len(set(h[:4]))<2)
        +
        # nobs
        # check if the suit of the 5th card (4, zero-indexed) matches the suit of any of the other 4 cards, and if it does is that card a Jack
        (a[4][1]in[j for i,j in a[:4]if i=="J"])
        +
        # runs
        s(reduce(lambda x,y:x*y,[b.count(k)for k in m])*len(m)for m in[d[s(x[:i]):s(x[:i])+j]for x in[[len(list(e))for i,e in groupby(j-i for i,j in E(d))]]for i,j in E(x)if j>2])

    # since only 0 evaluates to false, iff z==0 return 19, else return z.
    print z or 19

Explanation for runs logic specifically:
# for each index and value in the list, add the value minus the index
# since the list is sorted and reduced to unique values, this means adjacent values will all be the same value after offset
# ex: "JD 3C 4H 5H | 5S" -> [2, 3, 4, 10] - > [2, 2, 2, 7]
z = []
for i,j in enumerate(d):
    z.append(j-i)

# group the values by unique value
# then add the length of the groups to the list
# ex: [2, 2, 2, 7] -> [2:[2,2,2], 7:[7]]
#     [2:[2,2,2], 7:[7]] -> [[3], [1]]
w = []
for i,e in groupby(z):
    w.append([len(list(e))])

# list is double-nested so that the combined list comprehension leaves "x" available in both places it is needed
z = []
for x in w:
    for i,j in enumerate(x):
        if j>2:
            # if the group length is larger than 2
            # slice the list of unique card values to obtain only run values
            # since the run can be anywhere in the list, sum the preceding lengths to find the start and end index
            a = d[ sum(x[:i]) : sum(x[:i])+j ]
            z.append(a)

w = []
for m in z:
    # get the number of times the value is in the entire hand
    # ex: "JD 3C 4H 5H | 5S" -> [2,3,4,4,10] and (2,3,4) -> [1, 1, 2]
    a = [b.count(k)for k in m]
    # multiply all values together
    # [1, 1, 2] = 1*1*2 = 2
    a = reduce(lambda x,y:x*y, a)
    # length of the run * number of duplicate values
    a *= len(m)
    w.append(a)

# sum the results of the runs
return sum(w)

Some quick golfing of the ifs to get to 584 bytes

Stax, 106 bytes
Çí╬Δ╓↔╥.L§º♦½┌§└─»◄G≤n▒HJ♀p$¼♥,Q¢▲»Δ÷♠º≈r↑Vo\b■┌4Üé∟]e:┬A½f║J4σ↔└ΓW6O?╧φ¡╫╠├√├ùß5₧k%5ê╜ò/Φ/7w╠█91I◘┬n≥ìk♂╪

Run and debug online!
Bonus for CP437: See those suits symbol in the packed Stax? Too bad that the clubs do not appear ...
The ASCII equivalent is
jc%7<~6(4|@Y{h"A23456789TJQK"I^mXS{{A|mm|+15=_%2=_:u*+f%HxS{{o:-u1]=f{%mc3+|Msn#*+y{H"SHCD"ImY:uc5*s!yNd:u;**HH++yN|Ixs@11#+c19?

Explanation
jc%7<~6(4|@Y...X...Y...c19?
j                              Split on space
 c%7<~                         Is it a crib hand? Put it on input stack for later use
      6(                       Remove "!" if it exists
        4|@                    Remove "|"
           Y                   Store list of cards in y
            ...X               Store ranks in x
                ...            Perform scoring for ranks
                   Y           Store suits in y
                    ...        Perform scoring for suits
                       c19?    If the score is 0, change it to 19

{h"..."I^mX
{        m     Map each two character string to
 h             The first character
  "..."I^      1-based index of the character in the string

S{{A|mm|+15=_%2=_:u*+f%H
S                          Powerset
 {                   f%H   Twice the number of elements that satisfy the predicate
  {A|mm                        Value of card. Take the minimum of the rank and 10
       |+15=                   Sum of values equal 15 (*)
            _%2=               Length is 2 (**)
                _:u            All elements are the same (***)
                   *+          ( (***) and (**) ) or (*)

xS{{o:-u1]=f{%mc3+|Msn#*+
xS                                Powerset of ranks
  {        f                      Filter with predicate
   {o                                 Sort
     :-u                              Unique differences between elements
        1]=                           Is [1]
            {%mc                  Length of all runs
                3+|M              Maximum of all the lengths and 3
                    sn#           Number of runs with maximal length
                       *          Multiplied by its length
                        +         Add to score

y{H"SHCD"ImY
y{        mY    For each two character string
  H"SHCD"I      0-based index of the second character in the string "SHCD"

:uc5*s!yNd:u;**HH++
:uc5*                 5 points if all cards have same suit
     s!               Not all cards have same suit (#)
       yNd:u          First four cards have same suit (##)
            ;         Not a crib hand (###)
             **HH++   4 points if (#) and (##) and (###), add to score

yN|Ixs@11#+
yN|I           Index of cards with the same suit of last card (not including itself)
    xs@        The rank at these indices
       11#     Number of Jacks with the same suit of last card
          +    Add to score

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


text:
Code Golf: What is the spaceship's fate? [floating point version]
This question is slightly harder than the ASCII art version. There is no art, and now you get to do some floating point arithmetic!
The Challenge
The U.S.S. StackExchange was traveling through the gravity field of planet cg-00DLEF when an astronomical explosion occurred on board. As the head programming officer of the ship, it is your job to simulate the trajectory of your ship in order to predict whether you will be forced to crash land in cg-00DELF's solar system. During the explosion, your ship was heavily damaged. Due to the limited free DEEEPRAROM* of the spaceship, you must write your program in as few characters as possible.
*Dynamically Executable Electronically Erasable Programmable Random Access Read Only Memory
The Simulation
Somewhat like the ASCII art version, there will be the idea of time-steps. In the other version, a time-step was a relatively large amount of time: the ship could travel way beyond the gravity of a planet in a single time-step. Here, the time-step is a much smaller unit of time due to the larger distances involved. One major difference, however, is the non-existence of cells. The spaceship's current location and velocity will be floating point numbers, along with the gravitational forces involved. Another change is the fact that planets now have a much larger size.
There will be up to three planets in the simulation. All three will have a specific location, radius, and gravity. The gravity for each planet is a vector that exerts a force directly towards the center of the planet. The formula to find the strength of this vector is (Gravity)/(Distance**2), where the distance is the exact distance from the ship to the center of the planet. This means that there is no limit to where gravity can reach.
At any specific time, the spaceship has a velocity, which is the distance and angle that it traveled from last time-step to now. The ship also has momentum. The distance that it will travel between the current time-step and the next is the sum of its current velocity added to all of the gravity vectors at its location. This becomes the spaceship's new velocity.
Each simulation has a time limit of 10000 time steps. If the spaceship travels inside of a planet (it is closer to the center of the planet than the planet's radius), then it crashes into that planet. If the spaceship does not crash into any planet by the end of the simulation, then it is presumed to have escaped from gravity. It is unlikely that the ship could be aligned so perfectly that it manages to stay in orbit for 10000 time-steps while crashing on the 10001st time-step.
Input
Input will be four lines to STDIN. Each line consists of four comma-delimited numbers. Here is the format of the numbers:
ShipLocX,ShipLocY,ShipVelX,ShipVelY
Planet1LocX,Planet1LocY,Planet1Gravity,Planet1Radius
Planet2LocX,Planet2LocY,Planet2Gravity,Planet2Radius
Planet3LocX,Planet3LocY,Planet3Gravity,Planet3Radius

If there are fewer than three planets, then the leftover lines will be filled with zeros for all values. Here is an example input:
60,0,0,10
0,0,4000,50
100,100,4000,50
0,0,0,0

This means that the spaceship is located at (60,0) and is traveling straight "up/north" at a rate of 10 units/time-step. There are two planets, one located at (0,0) and one at (100,100). Both have a gravity of 4000 and a radius of 50. Even though all of these are integers, they will not always be integers.
Output
Output will be a single word to STDOUT to tell whether the spaceship has crash landed or not. If the ship crash lands, print crash. Otherwise, print escape. Here is the expected output for the above input:
crash

You may be wondering what happened. Here is a Pastebin post that has a detailed flight log for the spaceship. Numbers aren't very good at helping people visualize the event so here is what happened: The spaceship manages to escape the gravity of the first planet (to its west) with the help of the gravity of the second planet (to its northeast). It moves north and then passes slightly to the west of the second planet, barely missing it. It then curves around the northern side of the planet and crashes into the eastern side of the second planet.
Some more cases for examination
60,0,10,-10
0,0,2000,50
100,100,1357.9,47.5
0,0,0,0

escape (due to the inverse square law, 2000 isn't much gravity if you are 60 units away)
0,0,0,0
100,100,20000,140
-50,-50,50,50
-100,-100,50,50

crash (the first planet is extremely massive and extremely close)
0,0,0,0
0,0,0,0
0,0,0,0
0,0,0,0

escape (this is an edge case: there are no planets and a straightforward interpretation would suggest that the spaceship is directly on top of the planets)
Rules, Restrictions, and Notes
This is code golf. Standard code golf rules apply. Your program should be written in printable ASCII characters only. You cannot access any sort of external database. You may write entries in any language (other than one that is specialized towards solving this challenge).
End Transmission

rofl DEEEPRAROM! — The planets' gravitational interaction isn't supposed to be simulated? Still not exactly expensive numerically then, but fair enough. — I assume the reference simulation uses standard Runge-Kutta 4th order integration, and our program must create equivalent results?

I haven't figured out how to do multiple planets interacting. The problem is that they will tend to just crash into each other immediately. Fixing this will require bumping the scale of the simulation up incredibly.

As for the Runge-Kutta method, I'm honestly not that advanced in math yet. :( What I did was to calculate the gravity at the ship's current location and add this to the ship's velocity, generating the ship's new velocity. I did this for each time step. I know that this is not completely accurate, but I found out that dividing the ship's starting velocity and the planets' gravity by 10 increases the accuracy of the simulation.

Ah, that would be Euler's method. For small enough time steps that one is accurate, too; yet Runge-Kutta or something else more sophisticated would be more interesting to implement IMO. Maybe I should devise my own challenge, I can't seem to be easily satisfiable...

@leftaroundabout Go ahead. You can make something like "simulate entire solar system using differential equations" or something fancy like that, or maybe add in the third dimension.

Python, 178 170 chars
p=input
a,b,c,d=p()
x=a+b*1j
v=c+d*1j
P=(p(),p(),p())
R='escape'
for i in' '*10000:
 for a,b,g,r in P:
  d=a+b*1j-x;v+=g*d/abs(d)**3
  if abs(d)<r:R='crash'
 x+=v
print R

You're in a complex mood today, aren't you?

yes, i am....

How can I compete with that?

@Neil: the code, or the witty banter?

Well the code.  The witty banter I can keep up with.

save 8 chars with function renaming: p=input, called with p()

Golfrun/GolfScript?, 243 232 chars
10000:M;n%(','%2/{{~}%}/{{M*}%}:_~:v;_:x;'escape':R;{[','%2/{{~M*}%}/]}%:P;
M,{;P{~\x{0\-}%{+~@+@@+[\]}:|~:d.[~0\-]{[+.2%~*\.-2%~*@\-\.3%~*\(;);~*+]}:&~);~sqrt:z
..**\~d@[`~0]\&@M.*/\{1$/}%v|:v;;z\<{'crash':R;}{}if}/x v|:x;}/R puts

Golfrun is a language I'm working on, born as GolfScript C interpreter, but soon drifted away someway; though I've written this code without using knowingly specific Golfrun features (except for sqrt), the test with the original GolfScript failed (I had to add the sqrt feature to the original code, I am not a Ruby guru but I believe the problem is not my tweaking).
The first problem with this solution is that Golfrun, as GolfScript, has no floating point math. It is "simulated" magnifying the numbers, hopefully in the correct way (but I am not 100% confident I've done it coherently).
Even so, the solution does not handle floating point numbers as input, so I had to magnify them by hand to have only integer numbers.
Trying to implement the algorithm in the Python code, I have also implemented bits of complex math in a rather "general" way. Manipulating the algorithm in order to avoid this, and/or inlining whenever possible, delaying  the definitions, could save other chars...
How do I know this code works? Indeed, I am not sure it does! But giving the examples as input (after "removing" points where they appear), it wrote the expected results, except for the "corner case" (which raises an exception in Python too)...


text:
Generate the list [1, 0, -1, 0, 1, 0, -1, 0, ...]
In the spirit of a question on math.se: given an integer n, return the integer in position n of the sequence [1, 0, -1, 0, 1, 0, -1, 0, ...]. Assume n >= 0.
Rules:

You may only use the operations -x, x+y, x-y, x*y, x/y, and xy, whatever their representations are in the language you choose.
Your function must be called a.
Your function must run in constant time for all n.

Example:
a=lambda n:((-1)**(n*n-n)//2)+(-1)**(n*n+n)//2))//2

Non-example (uses list subscripting operation and modulo operator):
a=lambda n:[1,0,-1,0][n%4]

Non-example (uses cos operation):
from math import *;a=lambda n:int(cos(n*pi/2))

Non-example (does not run in constant time and uses if operation):
a=lambda n:-a(n-2) if n>1 else 0 if n>0 else 1

Clarifications: Both integer and float division are allowed. Your solution may return either an integer or a float (or complex number, I suppose, since some answers already used it). If your solution returns a float: your solution should, if it were to theoretically be carried out to infinite precision, give the exact answer.

Is the allowed x/y any kind of division (including div) or always floating point division? — Certainly, "Your function must run in constant time for all n" is limited to some reasonable limit, no need to work for bigInts?

What about conditionals, Boolean negation, etc?

Your example uses ** and // but you didn't allow them. a) What does ** and // mean, and why can you use them?

@user unknown: Sorry I didn't make that clear. x**y is x to the yth power and x//y is integer division.

@Peter Taylor: Conditionals, boolean negation, and such are not allowed. My real goal here was to translate that math problem I linked into a code golf problem.

Um. Conditionals, Boolean algebra, etc. are perfectly cromulent mathematical objects.

@Peter Taylor: Of course they are, but the author of the other question on math.se asked for solutions that used only things you would find on a basic pocket calculator. I wanted to stay true to that restriction.

In that case you should have disallowed exponentiation and complex numbers. Too late now, but next time you might want to post your question on the sandbox thread in meta to get a bit of feedback before people start answering.

How does the restriction on the name of the function work in languages where functions can't be named, or where a isn't a valid function name?

Also: It's impossible to solve this in constant time. Reading n takes time O(log n). VTC as unclear.

@user202729 This is incorrect.  You do not actually need to read the input, since the output is periodic (with period) you only need to read the last 2 bits.  Hypothetically if your input is provided as a bit stream you can do this in constant time.  However it does not look like any of the answers here actually do that.

@HatWizard in little endian. ... not a bad point.

Ruby, 26 characters
a=->n{1-(k=n-n/4*4)+k/3*2}

Example:
> p (0..10).map{|n| a[n]}
[1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1]

Note: This solution assumes that integer division / is an allowed operation.

I know it's been 6 years (lol..), but it can be golfed by 1 byte by reusing n instead of using a new variable k: a=->n{1-(n-=n/4*4)+n/3*2}. Try it online 25 bytes.

Python, 29 chars
a=lambda n:(1j**n+(-1j)**n)/2

Kind of cheating, but fun.
Edit:
Now that we can return complex numbers, this is competitive and no longer cheating (with Howard's suggestion).

I think that operator .real is not supported by the rules. You may use (j**n+(-j)**n)/2 instead.

Should be 1j**-n.

1j**-n instead of (-1j)**n saves 2 bytes.

C, 36 chars
a(n){return(1-n+n/2*2)*(1-n+n/4*4);}

The same function used by Peter Taylor.

By using a(n){return(n-n/2*2)*(2-n+n/4*4);} you can shave off two characters.

@Superbest, this gives the series shifted by one position. Close, but not it.

According to http://codepad.org/sO0mFkhI output from your function is 0, -1, 0, 1, 0, -1, 0, 1, 0, .... Output from mine is 1, 0, -1, 0, 1, 0, -1, 0, 1. The original question gives the example output 1, 0, -1, 0, 1, 0, -1, 0, ....

@Superbest, you seem to start with n=1, I start with n=0. All examples (except the first, which gives a syntax error), give a(0)=1, like my answer. You can say your suggestion is valid, because it gives the same series starting from another position, but I'll stick with my version.

Ah, that's right. I'm not sure why I thought the first one was 1 not 0. Sorry.

C is best! thanks for algorithmic approach!

I know it's been almost six years (lol..), but you can golf it to a(n){return 1-(n-=n/4*4)+n/3*2;} by creating a port of Howard's answer. Try it online 32 bytes.

Python, 36 chars
a=lambda n:(-1)**(n/2)*(1+(-1)**n)/2

J, 18 characters
a=:[:{.[:+._1^2%~]

Works, but is probably cheating by the rules set out above.
Calculates -1 to the power of the given integer divided by 2 which gives 0j1 for any odd number. The {. and the +. return the real part so that the odd numbers give 0.
Usage:
   a 1
0
   a 6
_1

Edit: After feeling a bit smug about this I've just looked properly at Keith's answers and realized I've done essentially the same thing.

GolfScript (20 19 chars)
{.4/4*-.3/2*)\-}:a;

This is a port of Howard's solution.
If, in addition to division, the remainder operation were permitted, this could be improved substantially (by 6 5 chars):
{.2%(\4%(*}:b;

Mathematically that's
x => (x%2 - 1) (x%4 - 1)

I can't see any logic behind excluding remainder, since it's defined in terms of permitted operations.

I think you should spend a semicolon after your code. Otherwise it interferes with the input to your program.

@Howard, I see your point. I think it's arguable, because the spec's badly worded, but on balance I think the leave-it-off position is weaker.

Python, 34 chars
Poor man's modulus... saves a whopping 2 chars over Keith Randall's solution.  Take that!  ;)
a=lambda n:(n-1-n/2*2)*(n-1-n/4*4)

edit: on reading others' solutions, this is the same as Peter Taylor's

bc: 28 chars
echo 'a=4;(1-a+a/2*2)*(1-a+a/4*4)' | bc

Python, 49 chars
a=lambda n:(lambda x:(x**3-3*x*x-x+3)/3)(n-n/4*4)

Note: In Python3 you'll have to replace n/4 with n//4 at the end.

8086 Assembler (14 bytes of machine code):
 ; ax holds the index into the sequence
 ; returns the sequence value in ax
 a: inc al
    shl al,6
    sar al,6
    cbw
    xor al,ah
    add al,ah
    cbw
    ret

But in machine code, it isn't named a. The name's only used by the assembler and by the linker, so you'd have to count the length of the assembly code or the object code (unless the OP clarifies that it's ok for the function to be named 0 instead, which would be the closest analogue to the name of a function in machine code).

TI-Basic, 12 bytes
i^Ans+i^-Ans
Ans/2

Store in prgmA and run with 5:prgmA, with the input in place of 5.
TI-Basic implicitly returns the last evaluated value.

Python 2, 28 bytes
a=lambda n:(n/2*2-n+1)*1j**n

Try it online!
Proof of validity for those who don't know Python:
The expression is (n/2*2-n+1)*1j**n. If you add parentheses, it becomes ((((n/2)*2)-n)+1)*(1j**n). / is integer division, since both n and 2 are integers in this case, * is multiplication, - is subtraction, + is addition and ** is exponentiation.

Java 8, 21 bytes
n->1-(n-=n/4*4)+n/3*2

Port of @Howard's Ruby answer.
Try it online.