在CodeGolf.SE上计算用户的特权


15

挑战

您的目标是编写尽可能短的程序,该程序将获取事件列表(例如upvote,downvote等),并返回用户的声誉和所获得的特权。

什么样的事件?

这是事件的图表,按赢得信誉的顺序列出:

-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

什么样的特权?

这是特权列表,按要求的信誉顺序。

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

输入值

输入(在STDIN上)将是事件的列表,每行一个,精确地显示它们在第一个图表中的显示方式(信誉值除外)。空行代表输入的结尾。这是一个示例(末尾应该有一个空白行):

join website
association bonus
answer upvoted
answer upvoted
question upvoted
answer accepted
answer upvoted
accept answer
unaccept answer
question unupvoted
accept answer
question upvoted

输出量

输出的第一行(到STDOUT)应命名累积的rep数量。此后的每一行都应列出所获得的一种特权,与显示的完全相同,并与第二张图表的顺序相同。上述输入的预期输出:

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

规则,限制和注释

这是代码高尔夫。适用标准代码高尔夫规则。

(编辑:由于我有两个访问文件的条目,我想指出,文件长度需要作为代码高尔夫标准规则的一部分添加到代码长度中)


“输入末尾的空白行”是指输入以两个换行符结尾还是仅以一个换行符结尾?
MvG 2014年

@MvG:我假设一个单行结束。
Konrad Borowski14年

“空白行”通常表示两个换行符。
Tobia 2014年

请注意,协会奖励不计入某些特权,但是我认为对于这项挑战可以忽略不计。
HyperNeutrino

Answers:


11

GolfScript(569 568 475 473个字符)

这使用不可打印的字符压缩所需的字符串,因此为xxd格式:

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*

模数字符串压缩,程序是

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*

在大多数方面,这都是微不足道的,但是有两个兴趣点。

第一个是输入字符串的哈希函数。令我惊讶的是,哈希函数为9个un不同的字符串(一旦删除)中的每个字符串都产生唯一结果的简单程度,而且,它为空字符串也产生不同的结果,这节省了从字符串中删除最后一个空白行的过程。输入。

单个行的rep的计算为

.'un'/''*.-1base'n?imdop
p_l'12*=110-@@={~)}*

首先,它un从字符串中删除,并记下是否找到了它。然后,它应用了一个超简单的哈希函数h(s) = ( sum over i: (-1)^i s[i] ) % 11。(您会发现我为什么对它感到惊讶)。字符串

'n?imdop
p_l'

是一个查找表,它将哈希值映射到rep中的更改(从ASCII值中减去110),然后如果un在开始时发现它,则该更改无效。

第二个兴趣点是特权的过滤器。我尝试了一个简单一些的方法:

{~^\<!},

对该行进行评估(未定义的单词不执行任何操作),以便获得其得分以与信誉进行比较(存储在中^)。它几乎可以工作。破坏它的是and发生在某些字符串中,并且是一个预定义的函数。解决方案:弄乱线条,使其and不再发生。(在某些情况下,删除空格会比删除字母更好a,但长度不会有任何区别)。


1
贪婪地寻找更好的替代表实际上比我的即席方法差一个字符。仍在研究启发式方法,以获取一种非贪婪的方法,以在内存耗尽之前运行完成。
彼得·泰勒

太棒了 甚至无法说出它如何计算声誉。
Lowjacker 2012年

8

红宝石1.9.3,514 467 459(507 460 452 + 7为标志)

与运行 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}

如果二进制字符串文字没有正确粘贴(它们可能没有正确粘贴),则这是一个十六进制转储:

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}

如果我没看错,您的“哈希”方案是将第7个字符和第11个字符连接起来?这是我没想到的一种方法,很有趣。
Gordon Bailey 2012年

5

Haskell,787个字符

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

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

4

电话-1083 1069

我意识到我对游戏有些迟了,但是C并没有代表我,所以我想我会为此而努力。

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

这是打高尔夫球的版本:

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

我认为基本思想与许多其他人的方法相似。我使用一些自制的哈希处理识别输入。散列方便地为空字符串提供零,从而使输入读取行非常紧凑。我确信哈希可以大大改善。通过对具有相同声誉的事物进行一些战略性哈希冲突,可以节省一些良好的角色。

我也有一些隐藏goto在宏中的反常乐趣(我第一次使用goto,我很自豪地说)。

我确定我有很大的改进空间的地方是输出部分。我什至没有尝试压缩实际的打印逻辑,所以我确定我也可以在其中保存一些字符。


您可以使用puts代替printf
Lowjacker 2012年

另外,您可以替换goto Ereturn(消除标签)并删除!=0哈希函数中的(这是多余的)。
Lowjacker 2012年

双方都很好,谢谢!
Gordon Bailey

希望你不要介意竞争
MvG 2014年

3

C(765737个字符)

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

或通过添加换行符和缩进使代码更具可读性:

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

上面的代码在文件末尾假设一个换行符。如果有两个,则需要写一个s+=*l?e[…]:0而不是s+=e[…],但要额外支付5个字符。写作while(*gets(l))会短一些,但也不会工作,因为我不包括头,所以编译器假定gets回报int不是char*

(l[11]%8^l[7])-97通过尝试以下形式的所有表达式,找到结果代码长度最短的表达式,可以找到哈希表达式:

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)

使用类似的蛮力搜索找到了合适的可打印ASCII字符表示形式。

Python 3(743715个字符)

本着与上述相同的精神。不过,这依赖于输入末尾的第二个换行符。

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)

2

Java-1519个字符

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

为了找到声誉,它在输入字符串中添加了所有字符(示例“加入网站”将添加到表格1219中),并且当b == 1219时,r = r + 1。


它是1518个字符,而不是1519个字符。删除新行将其减少到1511个。可以进一步改进答案,因为方法cif检查是否应该返回a true或a false,因为可以直接boolean从其中返回该值,if从而将大小减小到1470。 ;)我建议您改善答案。它正在等待同行审查:)
javatarz 2014年

我的编辑(由于某种原因)未被接受。我将我的答案重新发布为帖子[不是我想要的,但是我没有看到其他方法:(]。链接:codegolf.stackexchange.com/a/18478/14156
javatarz 2014年

2

斯卡拉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))}

从头开始重写。如果必须计算数据,直接包含数据会比较便宜(虽然很丑)。

第一种方法,从文件中读取事件价格和特权选项卡:

从文件读取数据: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))}

您似乎正在访问文件,该文件必须包含在程序的长度中。
PhiNotPi 2012年

@PhiNotPi:嗯-我知道我们必须遵守相同的规则。在阅读lone-sharks帖子中的评论之前,我只是开始解决方案。现在我需要一些时间来告别顶部数462和招呼1322
用户未知的

@PhiNotPi:我觉得你不错,但我不认为你是对的。其他大多数答案都是使用更昂贵的方法真诚地给出的。
用户未知

@PhiNotPi:在meta上使用新的挑战之前,最好在meta上使用沙箱获取帮助来解决此类问题。
hammar 2012年

1

J(704)

该程序包括四个部分:

  1. 以下解码器脚本(277字节)

    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. 一个二进制单词文件,w也称为277字节(在此处下载)。

    文件格式如下:每个字被编码为一组五位的“字节”。每组五个位的值可以从127代表字母,也0可以是分隔符。事件和特权描述中的每个唯一词都存储在此处。

  3. 一个二进制事件文件,名为e,为54个字节(在此处下载)。

    每个事件都包含一个12字节的信誉和一个或多个6字节的字。例如,accept answer编码如下:

     rep+15       Nwords  word1    word2
     000000010001 010     000110   011101
     17           2       6        29     <- these are indices in "w"
                          "accept" "answer"
    
  4. 二进制特权文件,称为p,大小为96字节(在此处下载)。

    文件格式与相同e,例如access to moderator tools,编码如下:

    rep+15       Nwords word1    word2  word3       word4
    011111011111 100    011010   011011 100000      010000
    2015         4      26       27     32          16
                        "access" "to"   "moderator" "tools"
    

0

Perl, 856 849个字符

$_="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]}

只是在一些分号后添加换行符以提高可读性;):

$_="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]}

0

Java(1470个字符)


注意:这是对Aman ZeeK Verma答案的修改,但是由于我的编辑未被接受并且我的答案明显短于他的答案,因此我将其张贴在这里。

可读版本:

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

缩小版:

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

0

PHP:676个字符

它不会赢得任何奖项,但是天哪,我只是想不出如何缩小它,所以我将其发布:

<?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
";

由于计算rep的部分很难阅读,因此这里需要额外的格式。它滥用未定义的常量,并使用@将其关闭:

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

您不必忽略警告。可以肯定地认为PHP不会返回错误或任何形式的错误。
Konrad Borowski14年

@xfix好吧,这给了我很多警告,所以我将用4个字节贿赂它以保持安静。
Boann 2014年

0

APL(549)

此数据以Unicode字符打包。

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'၌񤀨󹎋ᦚ𿻈㋘爁󤋦㲦󈂍󸜈节򜅩殃򛱨䇍򰈘𑢅򴊕𱄆򺈍𐥽𠪐𝵐񘥔򿔩󩾼󄵚񓽸󅘡򉸭򍢥󫧞󀮯򿆷𡑶󭗆󽞤󽀀'


0

Python 3.x(801个字符)

到目前为止,我所能做的最好,只是需要设计出比base64更好的编码(提示:有人可以提供帮助吗?)。

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())
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.