अपनी स्टैक एक्सचेंज प्रतिष्ठा की गणना करें


13

पृष्ठभूमि:

मुझे अक्सर लगता है कि, एक Stackexchange साइट ब्राउज़ करते समय, मुझे आश्चर्य होता है कि लोगों को उनकी प्रतिष्ठा की मात्रा कैसे मिलती है। मुझे पता है कि मैं हमेशा अपनी समस्याओं को हल करने के लिए कोडगोल्फ एसई पर भरोसा कर सकता हूं, इसलिए यहां यह है:

एक प्रोग्राम बनाएं जो एक सकारात्मक पूर्णांक को स्वीकार करेगा जो किसी व्यक्ति की प्रतिष्ठा का प्रतिनिधित्व करता है। हम बाउंटीज़ को नज़रअंदाज़ कर देंगे, और कहेंगे कि ये SE पर पूरा लाभ पाने / खोने का एकमात्र तरीका है (पूर्ण तालिका यहाँ ):

  • हर खाता 1 प्रतिनिधि के साथ शुरू होता है और उसके नीचे नहीं जा सकता
  • आपके प्रश्न का उत्थान = +5 है
  • आपका उत्तर ठीक है = +10
  • आपका प्रश्न नीचे -2 है
  • आपका उत्तर नीचे दिया गया है = -2
  • आप एक उत्तर को छोड़ दें = -1
  • आपका उत्तर स्वीकार किया जाता है = +15
  • आप एक उत्तर स्वीकार करते हैं = +2

आपके प्रोग्राम को यह पता लगाना होगा कि उस उपयोगकर्ता के खाते में कितनी कार्रवाई हुई थी, जो उसके पास है। इस स्तर के प्रतिनिधि को प्राप्त करने के लिए उसे कम से कम क्रियाओं का पता लगाना चाहिए। उदाहरण:

इनपुट: 11 आउटपुट: 1 उत्तर अपवोट

इनपुट: 93 आउटपुट: 6 उत्तर स्वीकार करता है, 1 उत्तर स्वीकार किया जाता है

इन उदाहरणों में जब मैं कहता हूं कि 'प्रश्न अपवोट' है, तो इसका मतलब है कि उस व्यक्ति की उत्थानशीलता उठी हुई है। जब मैं कहता हूं कि 'उत्तर अस्वीकृत' है, तो इसका मतलब है कि उन्होंने किसी और के उत्तर को अस्वीकार कर दिया है।

नियम:

, इसलिए सबसे छोटा कोड जो इस जीत को कर सकता है।


8
किसी भी प्रतिष्ठा को प्राप्त करने के लिए अनंत तरीके हैं। केवल "उत्तर अपवोट" और "उत्तर डाउनवोटेड" को लागू करना हमेशा एक रास्ता खोजने के लिए पर्याप्त है, इसलिए स्कोर परिवर्तनों के किसी भी व्यापक सबसेट का उपयोग करने के लिए कोई प्रोत्साहन नहीं है। क्या आपका यही इरादा है?
एल्गोरिथमशार्क

@algorithmshark संपादित किया गया। आपको सबसे कम संख्या में क्रियाएं मिलेंगी जो आपको वहां
मिलेंगी

"" "मुझे अक्सर लगता है कि, एक स्टेक्सएक्सचेंज साइट को ब्राउज़ करते समय, मुझे आश्चर्य होता है कि लोगों को उस प्रतिष्ठा की राशि कैसे मिलती है जो उनके पास है।" "" बनाम "" "आपको सबसे कम संख्या में क्रियाएं मिलनी चाहिए जो आपको वहां मिलेंगी" ""। दूसरी बोली पहले उद्धरण का सही उत्तर नहीं है।

1
@algorithmshark सामान्य तौर पर मैं आपकी टिप्पणियों से सहमत हूं। हालाँकि 6 उत्तर स्वीकार करता है + 1 उत्तर स्वीकृत 6 * 15 + 2 = 92 है, न कि 93! मैं इसे 7 कार्यों में करने का एक तरीका नहीं देख सकता, लेकिन मैं इसे 8: 6 उत्तर में स्वीकार कर सकता हूं, एक प्रश्न अपवोट, एक प्रश्न डाउनवोट: 6 * 15 + 5-2 = 93। डॉक्टर, अगर "छोटी संख्या में कार्यों के लिए एक से अधिक संभावनाएं हैं" तो क्या हमें उन सभी या सिर्फ एक को खोजना होगा?
लेवल रिवर सेंट

1
@steveverrill आप 1 प्रतिनिधि से शुरू करते हैं
TheDoctor

जवाबों:


3

गोल्फस्क्रिप्ट, 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

बैश, 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प्रतिष्ठा प्राप्त करने के लिए घटनाओं की न्यूनतम संख्या ), यह a16 से नीचे की प्रतिष्ठा (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पतन के लिए सरल नहीं है ।
AL

6

पर्ल, 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 का पूर्वाग्रह जोड़ा गया।
  • कुछ बाइट्स को बचाने के लिए अधिकांश चर कुछ अन्य चाल को हटाने के लिए फिर से लिखते हैं।

इस के अनुसार, जॉन स्कीट के पास 44084 उत्तर स्वीकार है और 1 उत्तर
अपवोट है

6
@ डॉक्टर: प्रश्न के अनुसार, 661266 की प्रतिष्ठा पाने के लिए ये न्यूनतम संख्या में कार्य हैं।
हेइको ओबर्डिएक

4

आर, 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

जावास्क्रिप्ट - 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)

वास्तव में बैश (हाँ!) के रूप में कई आकर्षण हैं, और पायथन और पर्ल :) की धड़कन है। यह प्रतिष्ठा को तब तक काट देता है जब तक 14कि इसके बाद यह अन्य आवश्यक क्रियाएं नहीं करता, पूरी तरह से लूप-स्टाइल।

EDIT 1: \ns को ,s में परिवर्तित किया और एक ifब्लॉक को टर्नरी, और छोटे नामों के साथ बेहतर फ़र्श में परिवर्तित किया ।

EDIT 2: अल्कोंजा का बड़ा धन्यवाद जिसने मुझे 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)

परीक्षा:

INPUT: 42
OUTPUT:

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

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

INPUT: 1337
OUTPUT:

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

अ-कोड कोड:

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

केवल पहला फ़ायरफ़ॉक्स ही क्यों?
TheDoctor

1
@ TheDoctor यह केवल फ़ायरफ़ॉक्स में उपलब्ध जेएस की सुविधा का उपयोग करता है - function name(args){}बन जाता है name=(args)=>{}और इस प्रकार बहुत सारे बाइट्स बचाता है।
गौरांग टंडन

@ TheDoctor मैंने अपने प्रोग्राम को क्रॉस-ब्राउज़र होने के लिए अपडेट किया है, और यह अब पहले की तुलना में बहुत छोटा है!
गौरांग टंडन

आपका वर्तमान संस्करण केवल 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 वाह! आपका बहुत बहुत धन्यवाद! मैं आखिरकार बैश के बहुत करीब हूँ! फिर से बहुत बहुत धन्यवाद!
गौरांग टंडन

1

गेम मेकर लैंग्वेज, 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

सी # - 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));

अन-गोल्फ - NEW

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

अन-गोल्फ - 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

पायथन - 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                                             |..|

आप प्रश्नों और उत्तरों के वोटों आदि की संख्या कैसे प्रदर्शित करते हैं? आपके कोड में ये स्ट्रिंग्स नहीं हैं (अन्य उत्तर देखें), इसलिए मुझे डर है कि आउटपुट नियमों के अनुरूप नहीं है।
AL

आउटपुट को भी गढ़ा जाता है क्योंकि उस बारे में कोई आवश्यकता नहीं थी। यह नीचे दिए गए प्रश्न / उत्तरों को अलग-अलग व्यवहार नहीं करता है क्योंकि दोनों -2 अंक देते हैं, जिसके परिणामस्वरूप जो सूची छपी है वह स्कोर प्राप्त करने के लिए सबसे छोटा अनुक्रम है।
लेमनबॉय

हां, नियम इस बिंदु के बारे में विवरण में नहीं जाते हैं। लेकिन आप देख सकते हैं कि अन्य उत्तरों में आउटपुट मानक है और X उत्तर स्वीकार करता है , Y उत्तर अपवोट्स इत्यादि प्रदर्शित करता है , लेकिन यह एक समस्या नहीं है क्योंकि आपके पास सबसे छोटा कोड नहीं है।
AL

@ लेमनबॉय मैंने इसे तीन दुभाषियों पर आज़माया है और यह काम नहीं करता है। सभी कहते हैं EOF। क्या आप मुझे एक संकलक की ओर संकेत कर सकते हैं जो काम करता है (और जिसे मुझे भविष्य में संदर्भ के लिए रखना चाहिए)?
गौरांग टंडन

1
@GaurangTandon आह, आप कॉफ़ीसेप्टिक दुभाषिया का उपयोग करके पायथन कोड चलाने की कोशिश कर रहे हैं
लेमनबॉय

1

C ++, 276 (316 w / शामिल)

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

जीसीसी के साथ चेतावनी के साथ संकलित करता है। उदाहरण:

$ ./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

जावास्क्रिप्ट - 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.loor | 0 दृष्टिकोण के लिए।

कुछ प्रांप्ट को प्रांप्ट पर ले जाया गया () परम, कुछ ब्रैकेट्स को हटा दिया, अंतिम स्ट्रिंग एपेंड के साथ अलर्ट।


Codegolf.SE में आपका स्वागत है! निर्देश कहते हैं: "एक प्रोग्राम बनाएं जो एक सकारात्मक पूर्णांक को स्वीकार करेगा" -> इसलिए आपको उपयोग करने की आवश्यकता होगी prompt, और मूल्य को हार्ड कोड नहीं कर सकता है।
गौरांग टंडन

कोई चिंता नहीं, शीघ्र संकेत (), जो इसे 161 तक टक्कर देता है।
मैट

@ GaurangTandon के स्मार्ट प्रॉम्प्ट () - 1 और अलर्ट आउटपुट दृष्टिकोण के बाद इसे और नीचे लाने के लिए। कुछ हार्डकोड स्ट्रिंग स्टोरेज को भी कम किया।
मैट

1

पायथन 3, 188 बी

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>जहां यह स्क्रिप्ट स्कोरकैम के रूप में सहेजी गई है।

नमूना उत्पादन:

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

स्वीकृत = स्वीकार + डी, डाउनवोट = डाउनवोट + डी, अपवोट दोहराया जाता है।
बिल वुडगेर

हां, लेकिन वे प्रतिस्थापन किसी भी चरित्र को समग्र रूप से नहीं बचाते हैं
अलेक्जेंडर-ब्रेट
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.