คำนวณชื่อเสียงการแลกเปลี่ยนสแต็คของคุณ


13

พื้นหลัง:

ฉันมักจะพบว่าเมื่อเรียกดูไซต์ Stackexchange ฉันเริ่มสงสัยว่าผู้คนได้รับชื่อเสียงในปริมาณเท่าไร ฉันรู้ว่าฉันสามารถพึ่งพา codegolf SE ได้เสมอเพื่อแก้ปัญหาของฉันดังนั้นนี่คือ:

สร้างโปรแกรมที่จะยอมรับจำนวนเต็มบวกซึ่งแสดงถึงชื่อเสียงของบุคคล เราจะเพิกเฉยต่อค่าหัวและบอกว่านี่เป็นวิธีเดียวที่จะได้รับ / เสียตัวแทนใน SE (ตารางเต็มที่นี่ ):

  • ทุกบัญชีเริ่มต้นด้วย 1 ตัวแทนและไม่สามารถลงไปด้านล่างได้
  • คำถามของคุณถูกโหวต = +5
  • คำตอบของคุณคือ upvoted = +10
  • คำถามของคุณถูกโหวต = -2
  • คำตอบของคุณคือ downvoted = -2
  • คุณลงคะแนนคำตอบ = -1
  • คำตอบของคุณได้รับการยอมรับ = +15
  • คุณยอมรับคำตอบ = +2

โปรแกรมของคุณจะต้องทราบว่ามีการกระทำเหล่านั้นเกิดขึ้นกี่ครั้งในบัญชีผู้ใช้นั้นเพื่อไปยังตัวแทนที่พวกเขามี มันจะต้องคิดออกจำนวนการกระทำที่สั้นที่สุดเพื่อไปที่ระดับของตัวแทนนี้ ตัวอย่าง:

อินพุต: 11 เอาต์พุต: 1 คำตอบ upvote

อินพุต: 93 เอาต์พุต: 6 คำตอบยอมรับยอมรับ 1 คำตอบ

ในตัวอย่างเหล่านี้เมื่อฉันพูดว่า 'question upvote' หมายถึงเควสท์ของบุคคลนั้นได้รับการโหวต เมื่อฉันพูดว่า 'answer downvote' หมายถึงพวกเขา downvote คำตอบของคนอื่น

กฎ:

ดังนั้นรหัสที่สั้นที่สุดที่สามารถทำสิ่งนี้ชนะ


8
มีวิธีมากมายในการรับชื่อเสียงที่ไม่ จำกัด การใช้ "answer upvote" และ "answer downvote" เพียงอย่างเดียวก็เพียงพอที่จะหาวิธีได้เสมอดังนั้นจึงไม่มีแรงกระตุ้นให้ใช้ชุดย่อยที่กว้างกว่าของการเปลี่ยนแปลงคะแนน นี่คือสิ่งที่คุณตั้งใจหรือไม่
algorithmshark

@algorithmshark แก้ไขแล้ว คุณต้องหาจำนวนการกระทำที่น้อยที่สุดที่จะพาคุณไปที่นั่น
TheDoctor

"" "ฉันมักจะพบว่าเมื่อเรียกดูไซต์ Stackexchange ฉันเริ่มสงสัยว่าผู้คนได้รับชื่อเสียงในจำนวนเท่าไร" "" vs "" "คุณต้องหาจำนวนการกระทำที่น้อยที่สุดที่จะพาคุณไปที่นั่น" "" การอ้างอิงที่สองไม่ใช่คำตอบที่ถูกต้องของคำพูดแรก

1
@algorithmshark โดยทั่วไปฉันเห็นด้วยกับความคิดเห็นของคุณ อย่างไรก็ตาม 6 คำตอบยอมรับ + ​​1 คำตอบที่ยอมรับคือ 6 * 15 + 2 = 92 ไม่ใช่ 93! ฉันไม่เห็นวิธีที่จะทำได้ใน 7 การกระทำ แต่ฉันสามารถทำได้ 8: 6 คำตอบยอมรับหนึ่งคำถามขึ้นโหวตหนึ่งคำถามลงคะแนน: 6 * 15 + 5-2 = 93 หมอถ้ามีความเป็นไปได้มากกว่าหนึ่งอย่างสำหรับ "จำนวนการกระทำที่น้อยที่สุด" เราต้องหาทั้งหมดหรือแค่หนึ่งอย่าง?
เลเวลริเวอร์เซนต์

1
@steveverrill คุณเริ่มต้นด้วย 1 ตัวแทน
TheDoctor

คำตอบ:


3

Golfscript, 162 144 ไบต์

{{}if}:?;~.)15/:^15*-:~3>1~8>' answer ':A' question 'if'upvote'++?^^A'accept'+:C+^1>{'s'+}??~5%:,4<,1>&1C'ed'++?,2%!1A'downvote'++,4<{'d'+}??]n*

มันทำงานอย่างไร

ความคิดทั่วไปคือตรงเช่นเดียวกับในคำตอบของฉันทุบตี

{{}if}:?;         # Create an `if' statement with an empty `else' block.
                  #
~.)15/:^          # Interpret the input string, subtract 1 from its only element (the
                  # reputation score), divide by 15 and save the result in `^'. This gives
                  # the number of accepted answers.
                  #
15*-:~            # Multiply the number of accepted answer by 15 and subtract the product
                  # from the reputation score. Save the result in `~'.
                  #
3>                # If the result is greater than 3:
                  #
  1               # Push 1 on the stack.
                  #
  ~8>             # If the result is greater than 8:
                  #
    ' answer ':A  # Push `answer' on the stack. Either way, save the string in `A'.
                  #
    ' question '  # Otherwise, push `question' on the stack.
                  #
  if              #
                  #
  'upvote'++      # Push `upvote' on the stack and concatenate the three strings.
                  #
?                 #
                  #
^                 # If the number of accepted answers is positive:
                  #
  ^A'accept'+:C+  # Push the number, concatenated with the string ` answer accept', on the
                  # stack. Either way, the string in `C'.
                  #
  ^1>             # If the number of accepted answers is greater than 1:
                  #
    {'s'+}        # Cocatenate the previous string with `s', for proper pluralization.
                  #
  ?               #
                  #
?                 #
                  #
~5%:,             # Calculate the reputation score modulus 5. Save the result in `,'.
                  #
4<,1>&            # If the result is less than 4 and greater than 1:
                  #
  1C'ed'++        # Push the string `1 answer accepted' on the stack.
                  #
?                 #
                  #
,2%!              # If the result is odd:
                  #
  1A'downvote'++  # Push the string `1 answer downvote' on the stack.
                  #
  ,4<             # If the result is less than 4:
                  #
    {'d'+}        # Concatente the previous string with `d'.
                  #
  ?               #
                  #
?                 #
                  #
]n*               # Join the array formed by all strings on the stack, separating the
                  # strings by newlines. This is the output.

9

Bash, 247 202 192 ไบต์

n=$1 bash <(sed 's/E/)echo /;s/C/ Aaccept/;s/A/answer /
s/.*)/((&)\&\&/'<<<'a=(n+1)/15,a-1)s=s;q=question
aE$aC$s
r=n%5,r-4)d=d&&
r>1E1Ced
1-r%2E1 Adownvote$d
n-=15*a,n>8)q=A
n>3E1 $q upvote')

มันทำงานอย่างไร

หลังจากคำสั่งsedทำงานแล้วสคริปต์ทุบตีต่อไปนี้จะถูกเรียกใช้งาน:

((a=(n+1)/15,a-1))&&s=s;q=question
((a))&&echo $a answer accept$s
((r=n%5,r-4))&&d=d&&
((r>1))&&echo 1 answer accepted
((1-r%2))&&echo 1 answer downvote$d
((n-=15*a,n>8))&&q=answer 
((n>3))&&echo 1 $q upvote

เพื่อให้ได้ทางออกที่ดีที่สุด (จำนวนเหตุการณ์น้อยที่สุดที่จะได้รับnชื่อเสียง) ก็เพียงพอที่จะคำนวณจำนวนคำตอบที่ยอมรับได้ ( a) ที่จำเป็นสำหรับการได้รับชื่อเสียงต่ำกว่า 16 (ยอมรับ 1 คำตอบ) และจัดการสิ่งตกค้างดังนี้

1  (no rep change)
2  answer accepted, answer downvoted
3  answer accepted
4  question upvote, answer downvote
5  question upvote, answer downvoted
6  question upvote
7  question upvote, answer accepted, answer downvoted
8  question upvote, answer accepted
9  answer upvote, answer downvote
10 answer upvote, answer downvoted
11 answer upvote
12 answer upvote, answer accepted, answer downvoted
13 answer upvote, answer accepted  
14 answer accept, answer downvote
15 answer accept, answer downvoted

2
ขอบคุณสำหรับคำอธิบายมันไม่ง่ายเลยที่จะจัดการ-2และลดระดับ-1โหวต
อัล

6

Perl, 500 263 256 208 ไบต์

สคริปต์rep.pl:

$_=1+pop;sub P($){print$=,@_,$/}$;=" answer ";$:="$;downvote";($==$_/15)&&P"$;accept"."s"x($=>1);$_%=15;$==1;P"$;upvote",$_-=10if$_>9;P" question upvote",$_-=5if$_>4;P"$;accepted"if$_>2;P$:."d"if$_%2;P$:if!$_

การใช้

อินพุตคาดว่าเป็นจำนวนเต็มบวกซึ่งกำหนดเป็นอาร์กิวเมนต์ของสคริปต์ การกระทำที่แตกต่างกันจะถูกส่งออกเป็นเส้น

การทดสอบ

perl rep.pl 11
1 answer upvote

perl rep.pl 93
6 answer accepts
1 answer accepted

perl rep.pl 1

perl rep.pl 4
1 question upvote
1 answer downvote

perl rep.pl 12
1 answer upvote
1 answer accepted
1 answer downvoted

perl rep.pl 19
1 answer accept
1 question upvote
1 answer downvote

perl rep.pl 34
2 answer accepts
1 question upvote
1 answer downvote

perl rep.pl 127
8 answer accepts
1 question upvote
1 answer accepted
1 answer downvoted

perl rep.pl 661266
44084 answer accepts
1 question upvote

Ungolfed

$_ = pop() + 1; # read the reputation as argument,
                # remove the actionless start reputation
                # and add a bias of two to calculate
                # the answer accepts in one division.

# Actions
# -------
# answer accepts:      Your answer is accepted    = +15
# answer upvotes:       Your answer is upvoted     = +10
# question upvotes:     Your question is upvoted   = +5
# answers accepted:     You accept an answer       = +2
# answers downvoted:    You downvote an answer     = -1
# answer downvotes:     Your answer is downvoted   = -2
# (questions downvoted: Your question is downvoted = -2) not used

# Function P prints the number of actions in $= and
# the action type, given in the argument.
# The function is prototyped "($)" to omit the
# parentheses in the usage.
sub P ($) {
    print $=, @_, $/ # $/ is the line end "\n"
}
# abbreviations,
# special variable names to save a space if a letter follows
$; = " answer ";
$: = "$;downvote";

# Calculation and printing the result
# -----------------------------------
($= = $_ / 15) && # integer division because of the special variable $=
P "$;accept" .
  "s" x ($= > 1); # short for: ($= == 1 ? "" : "s")
$_ %= 15;
$= = 1;           # now the action count is always 1 if the action is used
P "$;upvote",         $_ -= 10 if $_ > 9;
P " question upvote", $_ -=  5 if $_ > 4;
P "$;accepted"                 if $_ > 2;
P $: . "d"                     if $_ % 2;
P $:                           if ! $_

รุ่นเก่ากว่า

$_ = pop() + 1; # read the reputation as argument
                # subtract start reputation (1)
                # add bias (2)

# Actions
# -------
# $= answer accepts:      Your answer is accepted    = +15
# $b answer upvotes:      Your answer is upvoted     = +10
# $c question upvotes:    Your question is upvoted   = +5
# $d answers accepted:    You accept an answer       = +2
# $e answers downvoted:   You downvote an answer     = -1
# $f answer downvotes:    Your answer is downvoted   = -2
# -- questions downvoted: Your question is downvoted = -2

# Calculaton of answer accepts by a simple division that is
# possible because of the bias.
$= = $_ / 15; # integer division because of the special variable $=
$_ %= 15;

# The older version of the calculation can be simplified further, see below.
# Also the older version did not use the bias.
#
# function E optimizes the construct "$_ == <num>" to "E <num>"
# sub E {
#     $_ == pop
# }
#
# $d = $e = 1 if E 1;       #  1 =     +2 -1
# $d++ if E 2;              #  2 =     +2
#
# $c = $f = 1 if E 3;       #  3 =  +5 -2
# $c = $e = 1 if E 4;       #  4 =  +5 -1
# $c++ if E 5;              #  5 =  +5
# $c = $d = $e = 1 if E 6;  #  6 =  +5 +2 -1
# $c = $d = 1 if E 7;       #  7 =  +5 +2
#
# $b = $f = 1 if E 8;       #  8 = +10 -2
# $b = $e = 1 if E 9;       #  9 = +10 -1
# $b++ if E 10;             # 10 = +10
# $b = $d = $e = 1 if E 11; # 11 = +10 +2 -1
# $b = $d = 1 if E 12;      # 12 = +10 +2
#
# $=++, $f++ if E 13;       # 13 = +15 -2
# $=++, $e++ if E 14;       # 14 = +15 -1

$b++, $_ -= 10 if $_ > 9;
$c++, $_ -=  5 if $_ > 4;

# Now $_ is either 0 (-2), 1 (-1), 2 (0), 3 (1), or 4 (2).
# The number in parentheses is the remaining reputation change.

# The following four lines can be further optimized. 
# $f++        if ! $_;    # "! $_" is short for "$_ == 0"
# $e++        if $_ == 1;
# $d = $e = 1 if $_ == 3;
# $d++        if $_ == 4;

# Optimized version of the previous four lines:

$f++ if ! $_;
$e++ if $_ % 2;
$d++ if $_ > 2;

# function P optimizes the printing and takes the arguments for "print";
# the first argument is the action count and the printing is suppressed,
# if this action type is not needed.
sub P {
    print @_, $/ if $_[0]
    # $/ is "\n"
}

# some abbreviations to save some bytes
$; = " answer ";
$D = "$;downvote";

# output the actions

P $=, "$;accept", ($= == 1 ? "" : "s");
P $b, "$;upvote";
P $c, " question upvote";
P $d, "$;accepted";
P $e, $D, "d";
P $f, $D

การแก้ไข

  • กรณีที่ 4 ได้รับการแก้ไข
  • นอกจากนี้ยังช่วยให้การคำนวณที่ทำได้ง่ายขึ้นโดยไม่ต้องวนซ้ำ
  • ไม่สามารถลบพหูพจน์ "s" Sไม่จำเป็นต้องใช้ฟังก์ชันอีกต่อไป
  • การคำนวณที่เหมาะสมที่สุดEไม่จำเป็นต้องใช้ฟังก์ชั่นอีกต่อไป
  • เพิ่มอคติ 2 อันเพื่อการคำนวณที่เหมาะสมที่สุด
  • เขียนใหม่เพื่อลบตัวแปรส่วนใหญ่จะใช้เทคนิคอื่นเพื่อบันทึกไบต์

ตามนี้จอน Skeetมี 44084 คำตอบตอบ & 1 คำตอบ upvote
TheDoctor

6
@TheDoctor: ตามคำถามเหล่านี้เป็นจำนวนน้อยที่สุดของการกระทำเพื่อรับชื่อเสียง 661266
Heiko Oberdiek

4

R, 454 421

r=as.integer(commandArgs(T)[1])-1;p=function(...){paste(...,sep='')};a='answer ';b='accept';e='ed';f='d';v='vote';d=p('down',v);u=p('up',v);q='question ';z=c();t=r%/%15;if(t>0){z=c(p(t,' ',a,b));r=r%%15;};if(r%in%(8:12))z=c(z,p(a,u));if(r%in%(3:7))z=c(z,p(q,u));if(r%in%c(1,2,6,7,11,12))z=c(z,p(a,b,e));if(r%in%(13:14))z=c(z,p(a,b));if(r%in%c(3,8,13))z=c(z,p(a,d));if(r%in%c(1,4,6,9,11,14))z=c(z,p(a,d,f));cat(z,sep=', ')

ขอบคุณเดนนิสสำหรับคำตอบของเขาซึ่งช่วยฉันได้มาก

เวอร์ชันที่ไม่ดี

# read input
r = as.integer(commandArgs(T)[1]) - 1

# shortcut to join strings (... will pass the parameter to paste() *as is*)
p = function(...) {paste(..., sep = '')}

# strings
a = 'answer '; b = 'accept'; e = 'ed'; f = 'd'
v = 'vote'; d = p('down',v); u = p('up',v)
q = 'question '

z = c()

# +15
t = r %/% 15;
if (t > 0) {
    z = c(p(t,' ',a,b))
    r = r %% 15
}

if (r %in% (8:12))              z = c(z,p(a,u));    # answer upvote
if (r %in% (3:7))               z = c(z,p(q,u));    # question upvote
if (r %in% c(1,2,6,7,11,12))    z = c(z,p(a,b,e));  # answer accepted
if (r %in% (13:14))             z = c(z,p(a,b));    # answer accept
if (r %in% c(3,8,13))           z = c(z,p(a,d));    # answer downvote
if (r %in% c(1,4,6,9,11,14))    z = c(z,p(a,d,f));  # answer downvoted

# print operations
cat(z,sep = ', ')

4

JavaScript - 270 237 227 206 192 ตัวอักษร

p=prompt,r=p()-1,a="1answer ",v="vote,";s=(r/15|0)+"answer accept,",r%=15;if(r>9)s+=a+"+"+v,r-=10;if(r>2)s+="1question +"+v,r-=5;r>0?s+=a+"accepted,":0;r<-1?s+=a+"-"+v:0;p(r&1?s+=a+"-voted":s)

ตัวอักษรมากที่สุดเท่าที่เป็น Bash (ใช่!) และเต้น Python และ Perl :) มันจะตัดทอนชื่อเสียงจนกระทั่ง14หลังจากที่มันใช้เวลาหลังจากนั้นมันจะทำการกระทำที่จำเป็นอื่น ๆ

แก้ไข 1: แปลง\ns เป็น,s และแปลงหนึ่งifบล็อกเป็น ternary และปูพื้นได้ดีขึ้นด้วยชื่อสั้น ๆ

แก้ไข 2: ขอบคุณมากสำหรับAlconjaที่ช่วยฉันลด11ตัวอักษร หลังจากนั้นฉันทำการแก้ไขเพิ่มเติมเพื่อลดจำนวนตัวอักษรอีก 2 ตัว


รุ่นเก่ากว่า:

r=prompt()-1,a="1answer ",q="1question ",v="vote,";s=(c=r/15|0)+"answer accept,",r-=c*15;if(r>9)s+=a+"+"+v,r-=10;if(r>2)s+=q+"+"+v,r-=5;r>0?s+=a+"accepted,":0;if(r<-1)s+=a+"-"+v;r&1?s+=a+"-voted":0;alert(s)

ทดสอบ:

อินพุต: 42
เอาต์พุต:

2answer accept,1answer +vote,1answer accepted,1answer -voted

/*I sincerely hope the output is clear and easy to make out*/

อินพุต: 1337
เอาต์พุต:

89answer accept,1answer accepted,1answer -voted

รหัส Ungolfed:

// different version from the golfed code
rep = prompt() - 1
string = ""

function $(z, c, k){
  while(rep > 0 && rep >= z - 2) c += 1 , rep -= z;

  if(c) string += c + k + "\n"
}

a=" answer ", q=" question "

$(15, 0, a + "accept")
$(10, 0, a + "upvote")
$(5, 0, q + "upvote")
$(2, 0, a + "accepted")

function _(z, c, str){
  while(rep <= z) c += 1, rep -= z

  if(c) string += c + str + "\n";
}

_(-2, 0, a + "downvote");
_(-1, 0, a + "downvoted");

alert(string);

ทำไมจึงเป็น Firefox ตัวแรกเท่านั้น
TheDoctor

1
@TheDoctor มันใช้คุณสมบัติของ JS ใช้ได้เฉพาะใน Firefox ปัจจุบัน - function name(args){}กลายเป็นname=(args)=>{}และทำให้ประหยัดมากไบต์
Gaurang Tandon

@TheDoctor ฉันได้อัปเดตโปรแกรมของฉันให้เป็นเบราว์เซอร์ข้ามและตอนนี้มันก็สั้นกว่าเดิมมาก!
Gaurang Tandon

เวอร์ชันปัจจุบันของคุณใช้เพียงqครั้งเดียวดังนั้นคุณจึงสามารถอินไลน์ได้ นอกจากนี้คุณสามารถวางcตัวแปรและทำแทนr%=15 r-=c*15ควรนำคุณลงไปที่ 195 ตัวอักษร ( r=prompt()-1,a="1answer ",v="vote,";s=(r/15|0)+"answer accept,",r%=15;if(r>9)s+=a+"+"+v,r-=10;if(r>2)s+="1question +"+v,r-=5;r>0?s+=a+"accepted,":0;if(r<-1)s+=a+"-"+v;r&1?s+=a+"-voted":0;alert(s))
Alconja

@Alconja ว้าว! ขอบคุณมาก! ในที่สุดฉันก็ใกล้กับ Bash มาก ๆ ! ขอบคุณมากอีกครั้ง!
Gaurang Tandon

1

ภาษาของ Game Maker, 276

p=real(keyboard_string())-1j="#"s=""z=" answer"w=" accept"x=" upvoted"+j;y=w+"ed"v=" question"u=" downvoted"if m=floor(p/15)s+=(m+z+y)+j;r=p-m*15if m=floor(r/10)s+=(m+z+x)r-=m*10if m=floor(r/5)s+=(m+v+x)r-=m*5n=floor(r/2)r-=n*2if m=r{n++;s+=(m+u+z)+j}s+=(n+y+z)show_message(s)

1

C # - 391

ค่อนข้างยาวและฉันยังไม่ได้ทดสอบอย่างละเอียด (มาก) :)

class R{void Main(string[] a){var r=int.Parse(a[0])-1;var a=new[]{15,10,5,2};var o=new List<string>();Func<int,string>y=z=>{var w="";if(z==15)w=" answer accepted";if(z==10)w=" answer upvotes";if(z==5)w=" question upvotes";if(z==2)w=" answer accepts";return w;};foreach(var x in a)if(r/x>0){o.Add(r/x+y(x));r-=(r/x)*x;}if(r==1)o.Add("1 question downvotes");Console.Write(string.Join(", ",o));

ยกเลิกการตีกอล์ฟ - ใหม่

class R
{
    void Main(string[] a)
    {
        var r = int.Parse("122")-1; // subtracts 1 from total rep
        var a = new[] {15,10,5,2};
        var o = new List<string>();

        Func<int,string> y = 
            z => 
                {
                    var w="";
                    if(z==15) w=" answer accepted";
                    if(z==10) w=" answer upvotes";
                    if(z==5) w=" question upvotes";
                    if(z==2) w=" answer accepts";
                    return w;
                };

        foreach(var x in a) {
            if (r/x>0) {
                o.Add(r/x+y(x));
                r-=(r/x)*x;
            }
        }

        if(r==1)
            o.Add("1 question downvotes");

        Console.Write(string.Join(", ",o));
    }
}

Un-golfed - OLD (409)

class R
{
    void Main(string[] a)
    {
        var r = int.Parse(a[0])-1; // subtracts 1 from total rep
        var v = new[] {" question"," answer"," downvotes"," upvotes"," accepts"," accepted"};
        var o = new List<string>();

        // Starts from 15, then checks all the lower values.
        if (r/15>0) {
            o.Add(r/15+v[1]+v[5]);
            r-=(r/15)*15; // automatic rounding down due to int
        }
        if(r/10>0) {
            o.Add(r/10+v[1]+v[3]);
            r-=(r/10)*10;
        }
        if(r/5>0) {
            o.Add(r/5+v[0]+v[3]);
            r-=(r/5)*5;
        }
        if(r/2>0) {
            o.Add(r/2+v[1]+v[4]);
            r-=(r/2)*2;
        }
        if(r==1) {
            o.Add("1"+v[0]+v[2]);
        }
        Console.Write(string.Join(", ",o));
    }
}

ทดสอบ:

> prog.exe 120

7 answer accepted, 1 answer upvotes, 2 answer accepts 

1

Python - 213 207

p,k=__import__('itertools').combinations_with_replacement,int(input())
t,m,u=[5,10,-2,-1,15,2],[],iter(range(0,k))
while not m:m=list(filter(lambda v:k-1==sum(v),p(t,next(u))))
print(''.join(map(chr,m[0])))

สาปแช่งชื่อฟังก์ชั่นที่ยาวนาน!

ตัวอย่าง: (ไม่สนใจบรรทัดใหม่ต่อท้าย)

$ echo "93" | python per.py | hexdump -C
00000000  0f 0f 0f 0f 0f 0f 02 0a                           |........|

$ echo "11" | python per.py | hexdump -C
00000000  0a 0a                                             |..|

คุณแสดงจำนวนคำถามและคำตอบการโหวตอย่างไร? รหัสของคุณไม่มีสตริงเหล่านี้ (ดูคำตอบอื่น ๆ ) ดังนั้นฉันจึงกลัวว่าผลลัพธ์จะไม่เป็นไปตามกฎ
อัล

เอาท์พุทเป็นกอล์ฟเกินไปเนื่องจากไม่มีข้อกำหนดเกี่ยวกับที่ มันไม่ได้ตอบคำถาม / คำตอบที่แยกกันเนื่องจากทั้งสองให้ -2 คะแนนรายการผลลัพธ์ที่พิมพ์ออกมานั้นเป็นลำดับที่สั้นที่สุดเพื่อให้ได้คะแนน
LemonBoy

ใช่กฎไม่ได้ลงรายละเอียดเกี่ยวกับจุดนี้ แต่คุณสามารถสังเกตเห็นว่าในคำตอบอื่น ๆ ผลลัพธ์คือมาตรฐานและ display X answer accept , Y ตอบ upvotesเป็นต้น แต่นั่นไม่ใช่ปัญหาเนื่องจากคุณไม่มีรหัสสั้นที่สุด
อัล

@LemonBoy ฉันได้ลองใช้ล่ามสามตัวแล้วมันไม่ทำงาน EOFทั้งหมดพูด คุณช่วยชี้ฉันไปที่ผู้รวบรวมซึ่งใช้ได้ (และฉันควรเก็บไว้เพื่อใช้อ้างอิงในอนาคต)
Gaurang Tandon

1
@GaurangTandon ถอนหายใจคุณกำลังพยายามเรียกใช้รหัส Python โดยใช้ตัวแปล
coffeescript

1

C ++, 276 (316 วัตต์ / รวม)

#include <stdio.h>
#include <stdlib.h>
p(int&q,int*d){int r;char*s[]={"downvoted","accepted","question","answer","upvoted"};
if(r=(q&&q>=*d)){q-=(*d?*d:2);printf("%s %s\n",s[*(++d)],s[*(++d)]);}return r;}main(
int n,char**v){int q=atoi(v[1]);int d[]={-1,3,0,0,3,1,5,4,2,10,4,3,15,1,3};n=15;while
(p(q,d+n-3)||(n-=3));}

คอมไพล์ด้วย GCC พร้อมคำเตือน ตัวอย่าง:

$ ./a.out 0
$ ./a.out 1
accepted answer
downvoted answer
$ ./a.out 2
accepted answer
$ ./a.out 5
question upvoted
$ ./a.out 10
answer upvoted
$ ./a.out 15
answer accepted
$ ./a.out 16
answer accepted
accepted answer
downvoted answer
$ ./a.out 17
answer accepted
accepted answer

รู้สึกอิสระที่จะย้ายสิ่งนี้ไปยังภาษาที่ไม่ต้องการการประกาศประเภทและโพสต์เป็นของคุณเอง


1

JavaScript - 273 256 235

p=prompt(s=j="\n")-1;z=" answer",w=" accept",x=" upvoted"+j,y=w+"ed",v=" question",u=" downvoted";if(m=p/15|0)s+=m+z+y+j;r=p-m*15;if(m=r/10|0)s+=m+z+x;r-=m*10;if(m=r/5|0)s+=m+v+x;r-=m*5;n=r/2|0;if(m=r-=n*2)n++,s+=m+u+z+j;alert(s+n+y+z)

รวมการคำนวณและการส่งออกและกอล์ฟรวมถึง 287 ทั้งหมด

แก้ไข: นำตัวแปรบางตัวออกมาให้สั้นลง

ลบ Math.Floor สำหรับ | 0 แนวทาง

ย้ายการเริ่มต้นบางอย่างไปที่พารามิเตอร์ prompt () ลบวงเล็บบางส่วนออกแล้วแจ้งเตือนด้วยการผนวกสตริงสุดท้าย


ยินดีต้อนรับสู่ codegolf.SE! คำแนะนำบอกว่า: "สร้างโปรแกรมที่จะยอมรับจำนวนเต็มบวก" -> ดังนั้นคุณจะต้องใช้promptและไม่สามารถเข้ารหัสค่า
Gaurang Tandon

ไม่ต้องกังวลเพิ่มพรอมต์ () ซึ่งกระแทกได้สูงสุด 161
แมตต์

การติดตาม @ GaurangTandon อย่างชาญฉลาดพรอมต์ () - 1 และแจ้งเตือนวิธีการส่งออกเพื่อให้เรื่องนี้ดำเนินต่อไป ลดที่จัดเก็บสตริงฮาร์ดโค้ดบางส่วนเช่นกัน
Matt

1

Python3, 188B

n=input()+1
a=n//15
n%=15
A='answer '
print("%d %saccepted\n%d %supvoted\n%d question upvoted\n%d accept %s\n%d downvote %s\n%d %sdownvoted"%(a,A,n//10,A,n%10//5,n%5>2,A,n%5%2,A,n%5==0,A))

การใช้งาน: python3 score.py <ret> 11 <ret>ที่ซึ่งสคริปต์นี้ถูกบันทึกเป็น score.py

ตัวอย่างผลลัพธ์:

$ python score.py
5543
369 answer accepted
0 answer upvoted
1 question upvoted
1 accept answer 
0 downvote answer 
0 answer downvoted

accept = accept + d, downvote = downvote + d, upvoted ถูกทำซ้ำ
Bill Woodger

ใช่ แต่การแทนที่เหล่านั้นไม่ได้ช่วยตัวละครใด ๆ โดยรวม - ลองดูแล้ว
alexander-brett
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.