Calculate a user's privileges on CodeGolf.SE

15

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)

PhiNotPi

Posted 2012-04-13T00:41:46.843

Reputation: 26 739

Note that the association bonus does not count towards certain priviledges, but I assume that that can be ignored for this challenge. – HyperNeutrino – 2017-04-19T12:35:04.883

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 – 2014-01-11T16:30:27.530

@MvG: I would assume one single line end. – Konrad Borowski – 2014-01-11T17:55:20.913

"blank line" usually means two newline characters. – Tobia – 2014-01-11T22:57:37.327

Answers

11

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).

Peter Taylor

Posted 2012-04-13T00:41:46.843

Reputation: 41 901

1The 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. – Peter Taylor – 2012-04-14T19:23:50.130

Awesome. Can't even tell how it computes the reputation. – Lowjacker – 2012-04-23T00:11:18.497

8

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}

Lowjacker

Posted 2012-04-13T00:41:46.843

Reputation: 4 466

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. – Gordon Bailey – 2012-04-23T02:36:22.150

5

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

hammar

Posted 2012-04-13T00:41:46.843

Reputation: 4 011

5

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);}

Cristian Lupascu

Posted 2012-04-13T00:41:46.843

Reputation: 8 369

4

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.

Gordon Bailey

Posted 2012-04-13T00:41:46.843

Reputation: 708

You could use puts instead of printf. – Lowjacker – 2012-04-23T00:05:12.280

Also, you can replace goto E with return (eliminating the label) and remove the !=0 in the hash function (it's redundant). – Lowjacker – 2012-04-23T00:15:11.207

Both good points, thanks! – Gordon Bailey – 2012-04-23T02:29:53.780

Hope you don't mind a bit of competition.

– MvG – 2014-01-11T14:56:28.170

3

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)

MvG

Posted 2012-04-13T00:41:46.843

Reputation: 726

2

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.

Aman ZeeK Verma

Posted 2012-04-13T00:41:46.843

Reputation: 609

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 :) – javatarz – 2014-01-13T10:33:30.210

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

– javatarz – 2014-01-14T10:55:41.417

2

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))}

user unknown

Posted 2012-04-13T00:41:46.843

Reputation: 4 210

You seem to be accessing a file, which needs to be included in the length of the program. – PhiNotPi – 2012-04-14T01:44:20.977

@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. – user unknown – 2012-04-14T03:39:25.220

@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. – user unknown – 2012-04-14T07:57:35.990

@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.

– hammar – 2012-04-14T09:21:03.043

1

J (704)

The program consists of four parts:

  1. 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'
    
  2. 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.

  3. 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"
    
  4. 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"
    

marinus

Posted 2012-04-13T00:41:46.843

Reputation: 30 224

0

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]}

Rob Starling

Posted 2012-04-13T00:41:46.843

Reputation: 131

0

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;}}

javatarz

Posted 2012-04-13T00:41:46.843

Reputation: 273

0

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);

Boann

Posted 2012-04-13T00:41:46.843

Reputation: 378

You don't have to ignore warnings. It's safe to assume that PHP won't return errors or any sort. – Konrad Borowski – 2014-01-14T19:59:06.820

@xfix Well it's giving me a heap of warnings so I'll bribe it with the 4 bytes to keep it quiet. – Boann – 2014-01-15T06:52:26.933

0

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'၌ᦚ㋘爁㲦节殃䇍'

marinus

Posted 2012-04-13T00:41:46.843

Reputation: 30 224

1"If you use Unicode, byte count should use UTF-8." This is 1064 bytes. – Boann – 2014-01-15T06:48:28.493

0

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())

Bardi Harborow

Posted 2012-04-13T00:41:46.843

Reputation: 101