Berechnen Sie die Reputation Ihres Stapelwechsels

13

Hintergrund:

Ich stelle oft fest, dass ich mich beim Durchsuchen einer Stackexchange-Site frage, wie die Leute zu dem Ansehen kommen, das sie haben. Ich weiß, ich kann mich immer darauf verlassen, dass codegolf SE meine Probleme löst.

Erstellen Sie ein Programm, das eine positive Ganzzahl akzeptiert, die den Ruf einer Person repräsentiert. Wir werden Kopfgelder ignorieren und sagen, dass dies die einzige Möglichkeit ist, Wiederholungen auf SE zu gewinnen / zu verlieren (vollständige Tabelle hier ):

  • Jedes Konto beginnt mit 1 Wiederholung und kann nicht darunter liegen
  • Ihre Frage wurde positiv bewertet = +5
  • Ihre Antwort wurde positiv bewertet = +10
  • Ihre Frage ist downvoted = -2
  • Deine Antwort ist downvoted = -2
  • Sie haben eine Antwort = -1 abgelehnt
  • Ihre Antwort wird angenommen = +15
  • Sie akzeptieren eine Antwort = +2

Ihr Programm muss herausfinden, wie viele dieser Aktionen auf dem Konto dieses Benutzers ausgeführt wurden, um zu dem Vertreter zu gelangen, den sie haben. Es muss die kürzeste Anzahl von Aktionen ermittelt werden, um diese Wiederholungsstufe zu erreichen. Beispiele:

Input: 11 Output: 1 Antwort upvote

Eingabe: 93 Ausgabe: 6 Antworten akzeptiert, 1 Antwort akzeptiert

Wenn ich in diesen Beispielen "Frage nach oben" sage, bedeutet dies, dass die Quest der Person nach oben bewertet wurde. Wenn ich sage, dass die Antwort abgelehnt wurde, bedeutet dies, dass sie die Antwort eines anderen abgelehnt haben.

Regeln:

, also gewinnt der kürzeste Code, der dies kann.

Der Doktor
quelle
8
Es gibt unendlich viele Möglichkeiten, einen bestimmten Ruf zu erlangen. Es reicht aus, nur "Antwort aufwärts" und "Antwort abwärts" zu implementieren, um immer einen Weg zu finden, sodass es keinen Anreiz gibt, eine breitere Teilmenge der Score-Änderungen zu verwenden. Ist es das, was du beabsichtigt hast?
Algorithmushai
@algorithmshark bearbeitet. Sie müssen die kleinste Anzahl von Aktionen finden, die Sie dorthin bringen
TheDoctor
"" Ich stelle oft fest, dass ich mich beim Durchsuchen einer Stackexchange-Site frage, wie die Leute zu dem Ansehen kommen, das sie haben. " "". Das 2. Zitat ist nicht unbedingt die richtige Antwort auf das 1. Zitat.
1
@algorithmshark Im Allgemeinen stimme ich Ihren Kommentaren zu. 6 Antworten akzeptiert + 1 Antwort akzeptiert ist 6 * 15 + 2 = 92, nicht 93! Ich kann keinen Weg finden, dies in 7 Aktionen zu tun, aber ich kann es in 8: 6 tun. Antwort akzeptiert, eine Frage positiv, eine Frage negativ: 6 * 15 + 5-2 = 93. Doktor, wenn es mehr als eine Möglichkeit für "kleinste Anzahl von Aktionen" gibt, müssen wir dann alle oder nur eine finden?
Level River St
1
@steveverrill Sie beginnen mit 1
Wiederholung

Antworten:

3

Golfscript, 162 144 Bytes

{{}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*

Wie es funktioniert

Die allgemeine Idee ist genau die gleiche wie in meiner Bash-Antwort .

{{}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.
Dennis
quelle
9

Bash, 247 202 192 Bytes

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

Wie es funktioniert

Nachdem der sed- Befehl seinen Job ausgeführt hat, wird das folgende Bash-Skript ausgeführt:

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

Um die optimale Lösung zu erhalten (minimale Anzahl von Ereignissen, um eine nReputation zu erhalten ), reicht es aus, die Anzahl der akzeptierten Antworten ( a) zu berechnen, die erforderlich sind, um eine Reputation unter 16 zu erreichen (1 Antwort akzeptieren), und den Rückstand wie folgt zu behandeln:

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
Dennis
quelle
2
Danke für die Erklärung, es ist nicht einfach zu behandeln -2und -1downvotes.
AL
6

Perl, 500 263 256 208 Bytes

Skript 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!$_

Verwendung

Die Eingabe wird als positive Ganzzahl erwartet, die dem Skript als Argument übergeben wird. Die verschiedenen Aktionen werden als Zeilen ausgegeben.

Tests

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 ! $_

Ältere Version

$_ = 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

Bearbeitungen

  • Fall 4 ist behoben.
  • Dies vereinfacht auch die Berechnung, die jetzt ohne Schleife durchgeführt wird.
  • Nicht erreichbarer Plural "s" entfernt, Funktion wird Snicht mehr benötigt.
  • Berechnung optimiert, Funktion Enicht mehr benötigt.
  • Vorspannung von 2 für optimierte Berechnung hinzugefügt.
  • Größeres Umschreiben, um die meisten Variablen zu entfernen. Einige andere Tricks, um einige Bytes zu sparen.
Heiko Oberdiek
quelle
nach diesem, Jon Skeet hat 44084 Antwort akzeptiert & 1 Antwort upvote
TheDoctor
6
@TheDoctor: Entsprechend der Frage ist dies die minimale Anzahl von Aktionen, um einen Ruf von 661266 zu erhalten.
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=', ')

Vielen Dank an Dennis für seine Antwort, die mir sehr geholfen hat.

Ungolfed-Version

# 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 = ', ')
AL
quelle
4

JavaScript - 270 237 227 206 192 Zeichen

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)

Genau so viele Zeichen wie Bash (yeah!), Und schlägt Python und Perl :) Es verringert die Reputation, bis 14es die anderen erforderlichen Aktionen ausführt, vollständig im Loop-Stil.

EDIT 1: Konvertiert \ns in ,s und konvertiert einen ifBlock in ternäre und bessere Bodenbeläge mit Kurznamen.

EDIT 2: Vielen Dank an Alconja , die mir geholfen hat, 11 Zeichen zu reduzieren . Danach habe ich noch einige Korrekturen vorgenommen, um 2 weitere Zeichen zu reduzieren.


Ältere Version:

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)

Prüfung:

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

Ungolfed Code:

// 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);
Gaurang Tandon
quelle
Warum ist der erste nur Firefox?
TheDoctor
1
@TheDoctor Nutzt die Funktion von JS, die derzeit nur in Firefox verfügbar ist - function name(args){}wird name=(args)=>{}und spart somit eine Menge Bytes.
Gaurang Tandon
@TheDoctor Ich habe mein Programm so aktualisiert, dass es browserübergreifend ist, und es ist jetzt viel kürzer als zuvor!
Gaurang Tandon
Ihre aktuelle Version wird nur qeinmal verwendet, sodass Sie sie einbinden können. Sie können die cVariable auch löschen und r%=15stattdessen ausführen r-=c*15. Sollte Sie auf 195 Zeichen bringen ( 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 Wow! Danke vielmals! Endlich bin ich Bash sehr, sehr nahe! Nochmals vielen Dank!
Gaurang Tandon
1

Game Maker Language, 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)
Timtech
quelle
1

C # - 391

Ein bisschen lang, und ich habe das nicht gründlich (viel) getestet. :)

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

Ungolfen - NEU

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

Ungolfen - ALT (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));
    }
}

Prüfung:

> prog.exe 120

7 answer accepted, 1 answer upvotes, 2 answer accepts 
jzm
quelle
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])))

Verfluchen Sie lange Funktionsnamen!

Beispiel: (ignorieren Sie die nachfolgende Newline)

$ 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                                             |..|
LemonBoy
quelle
Wie wird die Anzahl der Fragen und Antworten angezeigt, Stimmen usw.? Ihr Code enthält diese Zeichenfolgen nicht (siehe die anderen Antworten). Ich fürchte, die Ausgabe entspricht nicht den Regeln.
AL
Die Ausgabe ist auch Golf, da es keine Anforderung dazu gab. Downvoted-Fragen / -Antworten werden nicht separat behandelt, da beide -2 Punkte ergeben. Die resultierende Liste, die gedruckt wird, ist die kürzeste Sequenz, um die Punktzahl zu erreichen.
LemonBoy
Ja, die Regeln gehen nicht auf Details zu diesem Punkt ein. Sie können jedoch feststellen, dass in den anderen Antworten die Ausgabe Standard ist und die X-Antwort akzeptiert , die Y-Antwort erhöht usw. Dies ist jedoch kein Problem, da Sie nicht den kürzesten Code haben.
AL
@LemonBoy Ich habe dies bei drei Dolmetschern versucht und es funktioniert nicht. Alle sagen EOF. Können Sie mich bitte auf einen Compiler verweisen, der funktioniert (und den ich zum späteren Nachschlagen aufbewahren sollte)?
Gaurang Tandon
1
@ GaurangTandon Seufz, Sie versuchen, Python-Code mit dem Kaffee-Skript-Interpreter
LemonBoy
1

C ++, 276 (316 W / Includes)

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

Kompiliert mit GCC mit Warnungen. Beispiel:

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

Sie können dies auf eine Sprache portieren, für die keine Typdeklarationen erforderlich sind, und als Ihre eigene Sprache veröffentlichen.

Jason C
quelle
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)

Kombinierte Berechnung und Ausgabe und Golf weiter auf insgesamt 287.

Bearbeiten: einige Variablen für einige kürzere herausgenommen.

Math.Floor für | 0-Ansatz entfernt.

Initialisierung zum prompt () - Parameter verschoben, einige Klammern entfernt, Warnung mit abschließendem String-Anhang.

Matt
quelle
Willkommen bei codegolf.SE! In den Anweisungen heißt es: "Erstellen Sie ein Programm, das eine positive Ganzzahl akzeptiert" -> Sie müssen promptden Wert also verwenden und können ihn nicht hart codieren.
Gaurang Tandon
Keine Sorge, fügte prompt () hinzu, was es auf 161 erhöht.
Matt
Befolgen Sie die intelligentere Eingabeaufforderung () - 1 von @ GaurangTandon und den Alarmausgabeansatz, um dies weiter zu verbessern. Reduziert auch einen Teil des Festplattenspeichers.
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))

Verwendung: python3 score.py <ret> 11 <ret> Hier wird dieses Skript als score.py gespeichert.

Beispielausgabe:

$ python score.py
5543
369 answer accepted
0 answer upvoted
1 question upvoted
1 accept answer 
0 downvote answer 
0 answer downvoted
Alexander-Brett
quelle
accept = accept + d, downvoted = downvote + d, upvoted wird wiederholt.
Bill Woodger
Ja, aber diese Ersetzungen speichern keine Zeichen insgesamt - versuchen Sie es und sehen Sie
Alexander-Brett