Fai un test a scelta multipla


14

Vi presento un test! Il tuo test è testare. Il test è quello di testare la testee con i test di un tester ti dà, in shor prova di quantità di codice. In particolare, eseguirai un test a scelta multipla che hai ricevuto come input.

In questa sfida, devi prendere un input come questo:

1. Our site is called Programming Puzzles & Code ________.
A: Debugging
*B: Golf
C: Hockey
D: Programming
2. What is the *most* popular tag on our site?
A: [debug]
B: [program]
*C: [code-golf]
D: [number]
E: [c++]
3. We are part of the ________ Exchange network.
*A: Stack
B: Code
C: Programmer
D: Hockey
4. Is this the first question?
A: Yes
*B: No
5. Is this the last question?
*A: Yes
B: No

Ed ecco un esempio del test che viene eseguito:

1. Our site is called Programming Puzzles & Code ________.
A: Debugging
B: Golf
C: Hockey
D: Programming
answer: B
correct!

2. What is the *most* popular tag on our site?
A: [debug]
B: [program]
C: [code-golf]
D: [number]
E: [c++]
answer: C
correct!

3. We are part of the ________ Exchange network.
A: Stack
B: Code
C: Programmer
D: Hockey
answer: B
incorrect! the answer was A

4. Is this the first question?
A: Yes
B: No
answer: B
correct!

5. Is this the last question?
A: Yes
B: No
answer: B
incorrect! the answer was A

overview:
3 correct, 2 incorrect (60%)

3. We are part of the ________ Exchange network.
you chose B: Code
the answer was A: Stack

5. Is this the last question?
you chose B: No
the answer was A: Yes

Specifica formale:

  • Ingresso
    • Se una linea inizia con un numero seguito da un punto e uno spazio, è una domanda con quel numero. I numeri inizieranno sempre da 1 e saliranno 1 per ogni domanda.
    • Se una riga inizia con un asterisco opzionale, una lettera, due punti e quindi uno spazio, è una risposta. Anche le risposte saranno sempre sequenziali. Ci sarà una sola risposta corretta per domanda.
    • Una linea non inizierà in altro modo rispetto ai modi precedentemente menzionati.
    • L'input può essere accettato in qualsiasi modo (lettura da un file, stdin, ecc.) Ma non deve essere codificato nel programma.
  • Uscita (fase di test)
    • Per prima cosa, stampa ogni domanda in sequenza. Stampa la domanda e le sue risposte come ricevute nell'input, ma non stampare l'asterisco che indica le risposte corrette.
    • Quindi, stampare una nuova riga e "answer: ". Attendi l'input dell'utente. L'input dell'utente corrisponderà sempre a una risposta.
    • Se la risposta corretta (quella con un asterisco) è la stessa di quella immessa dall'utente, viene emessa "correct!". Altrimenti, output "incorrect! the answer was " + correct_letter.
    • Separare ogni domanda con una riga vuota, quindi ripetere i passaggi di output precedenti fino a quando non ci sono più domande.
  • Uscita (fase panoramica)
    • Stampa "overview: "e poi una riga.
    • Stampa "{number of correct answers} correct, {incorrect answers} incorrect ({percent correct, rounded to the nearest whole number}%)"(ovviamente sostituendo le frasi tra parentesi graffe con i rispettivi valori). Quindi stampare una riga vuota per la spaziatura.
    • Ora, per ogni domanda errata, stampare la domanda (non le sue risposte), quindi su una nuova riga "you chose " + answer_you_chosee su un'altra riga "the answer was " + correct_answer. Separare la panoramica di ogni risposta errata con una riga vuota.
  • Per ridurre i cheat interpretando le cose letteralmente, quando viene fornito lo stesso output qui e lo stesso input nella fase di test, il tuo programma deve produrre esattamente lo stesso output del campione.

Questo è ; vince il codice più corto! (E ottiene un A + (segno di spunta verde)!)


2
Bella sfida, ma vorrei che il test di esempio per contenere situazioni forse difficili, come \d\. , \w: e \*nel bel mezzo di domande / risposte. (Ad esempio attualmente è *possibile eliminare con y/*//, mentre il modo corretto è lungo come s/^\*//.)
manatwork

2
Dobbiamo consentire la continuazione della linea? Voglio dire, ci saranno linee che non iniziano con “1. "O" A: "? In caso affermativo, includere tali casi nel test di esempio.
arte

@manatwork (primo commento) Ok, modifica (secondo commento) no, no. Chiarirò.
Maniglia della porta

1
Quindi, come hai intenzione di testare questo test?
Joe Z.

2
@JoeZ. Umm ... non sono sicuro di cosa intendi ... Ho fornito un test case per il test per testare il tuo tester
Doorknob

Risposte:


2

Perl 5, 279

$y=correct;@w=(the,$n=answer,was);map{s/^\*((.+?):.+)/$a=$1/me;print"$_$n: ";chop($@=<>);print$@eq($l=$2)?++$d&&"$y!

":(/^\d.+/,$o.=$&,/^$@.+/m,$o.="
you chose: $&
@w $a

")&&"in$y! @w $l

"}@_=split/(?=^\d)/m,join"",<>;printf"overview:
$d $y, %d in$y (%d%)

$o",@_-$d,$d/@_*100

Nota: le nuove righe sono necessarie per la formattazione dell'output.

Ogni volta che penso di non poter più giocare a golf, imparo qualcosa di nuovo! Sta lentamente diventando più punteggiatura del testo leggibile ... Penso che sia una buona cosa?

Utilizzo: perl -e '...' test.txto perl test.pl test.txt.

Se scegli un'opzione non presentata nell'elenco, otterrai un risultato errato nella panoramica ( you chose: 1. Our site is called Programming Puzzles & Code ________.ad esempio dirà ).

Esempio di esecuzione


Si prega di mostrare un esempio di input e output.
DavidC,

@DavidCarraher ha aggiunto un link aggiornato all'output tramite showterm.io . Pensavo che sarebbe leggermente migliore dell'output statico, anche se non lo cattura esattamente come nel terminale.
Dom Hastings,

Ciò offre una buona visione di come funziona il tuo programma.
DavidC

3

Mathematica 144

Questo potrebbe essere un tentativo non valido. Ho separato la domanda da ogni risposta nell'input. Ho anche indicato la risposta corretta con una lettera in un campo separato, anziché un asterisco prima dell'alternativa.

Comunque...

I dati

questions={{{"\n1. Our site is called Programming Puzzles & Code ________.\n","A: Bugging\n","B: Golf\n","C: Hockey\n","D: Programming\n"},"B"},{{"\n2. What is the most popular tag on our site? \n","A: [debug]\n","B: [program]\n","C: [code golf]\n","D: [number]\n"},"C"},{{"\n3. We are part of the _______ Exchange network. \n","A: Stack\n","B: Code\n","C: Programmer\n","D: Hockey\n"},"A"},{{"\n4. Is this the first question? \n","A: Yes\n","B: No\n"},"B"},{{"\n5. Is this the last question? \n","A: Yes\n","B: No\n"},"A"}};

Codice

Una risposta a ciascuna domanda viene inserita attraverso una finestra di dialogo. Vengono stampate domande, risposte e feedback.

f@x_:=
Print[If[((r=ChoiceDialog[Print[""<>#,"\nanswer: "];""<>#,StringTake[Rest@#,1]])==#2),
r<>"\ncorrect!", r<>"\nincorrect, the answer is "<>#2]&@@x] 

Test

f /@ questions

scelta della finestra di dialogo


wow, impressionante! l'input non è nella forma corretta però ... comunque, è davvero notevole per la brevità del codice e quanto costa!
Maniglia della porta

Grazie. Naturalmente è possibile massaggiare la stringa di input in una struttura compatibile con Mathematica, ma avrebbe nascosto l'eleganza alla base della presente soluzione non ammissibile.
DavidC,

Bello. Quattro caratteri più brevi:g@{a_,b_}:=Print[If[(r=ChoiceDialog[Print[""<>a,"\nanswer: "];""<>a,Rest@a~StringTake~1])==b,r<>"\ncorrect!",r<>"\nincorrect, the answer is "<>b]]
Mr.Wizard,

E salvane uno in più usando Print@If[...]anziché Print[If[...]].
Mr.Wizard,

2

Java - 1210

int i,o;String q;String[]s={"1. Our site is called Programming Puzzles & Code ________.\n","2. What is the most popular tag on our site?\n","3. We are part of the ________ Exchange network.\n","4. Is this the first question?\n","5. Is this the last question?\n"},b={"B","C","A","B","A"},p=new String[5];String[][]a={{"A: Debugging\n","B: Golf\n","C: Hockey\n","D: Programming\n","answer: "},{"A: [debug]\n","B: [program]\n","C: [code-golf]\n","D: [number]\n","E: [c++]\n","answer: "},{"A: Stack\n","B: Code\n","C: Programmer\n","D: Hockey\n","answer: "},{"A: Yes\n","B: No\n","answer: "},{"A: Yes\n","B: No\n","answer: "}};java.util.Map<String,Integer>m=new java.util.HashMap(){{put("A",0);put("B",1);put("C",2);put("D",3);put("E",4);}};java.util.Scanner u=new java.util.Scanner(System.in);for(i=0;i<5;i++){q=s[i];for(o=0;o<a[i].length;)q+=a[i][o++];System.out.print(q);if(b[i].equals(p[i]=u.nextLine()))q="correct!";else q="incorrect! the answer was "+b[i];System.out.println(q+"\n");}q="";o=0;for(i=0;i<5;i++)if(b[i].equals(p[i]))o++;else q+=s[i]+"you chose "+a[i][m.get(p[i])]+"the answer was "+a[i][m.get(b[i])]+"\n";System.out.println("overview:\n"+o+" correct, "+(5-o)+" incorrect ("+o*100/5+"%)\n\n"+q);

formattato: 1980

String[] s = {"1. Our site is called Programming Puzzles & Code ________.\n",
        "2. What is the most popular tag on our site?\n",
        "3. We are part of the ________ Exchange network.\n",
        "4. Is this the first question?\n",
        "5. Is this the last question?\n"};
    String[][] a = {
        {"A: Debugging\n", "B: Golf\n", "C: Hockey\n", "D: Programming\n", "answer: "},
        {"A: [debug]\n", "B: [program]\n", "C: [code-golf]\n", "D: [number]\n", "E: [c++]\n", "answer: "},
        {"A: Stack\n", "B: Code\n", "C: Programmer\n", "D: Hockey\n", "answer: "},
        {"A: Yes\n", "B: No\n", "answer: "},
        {"A: Yes\n", "B: No\n", "answer: "}};

    java.util.Map<String, Integer> m = new java.util.HashMap<String, Integer>() {
        {
            put("A", 0);
            put("B", 1);
            put("C", 2);
            put("D", 3);
            put("E", 4);
        }
    };
    String[] b = {"B", "C", "A", "B", "A"};
    String[] p = new String[5];
    java.util.Scanner u = new java.util.Scanner(System.in);
    String q;
    int i;
    int o;
    for (i = 0; i < 5; i++) {
        q = s[i];
        for (o = 0; o < a[i].length;) {
            q += a[i][o++];
        }
        System.out.print(q);
        if (b[i].equals(p[i] = u.nextLine())) {
            q = "correct!";
        } else {
            q = "incorrect! the answer was " + b[i];
        }
        System.out.println(q + "\n");
    }
    q = "";
    o = 0;
    for (i = 0; i < 5; i++) {
        if (b[i].equals(p[i])) {
            o++;
        } else {
            q += s[i] + "you chose " + a[i][m.get(p[i])] + "the answer was " + a[i][m.get(b[i])] + "\n";
        }
    }
    System.out.println("overview:\n" + " correct, " + (5 - o) + " incorrect (" + o * 100 / 5 + "%)\n\n" + q);

Questo non sarà certamente il più breve ma è tutto autonomo


0

Haskell, 598

import System.Environment
import System.IO
n=putStrLn
p=putStr
d#s=p$show d++s
v&(m:a)=n m>>q[]""a>>= \(r,(s,t))->n s>>n"">>b v m t&r
(r,w,s)&[]=n"overview:">>r#" correct, ">>w#" incorrect (">>((100*r)`div`(r+w))#"%)\n">>mapM_ n s
b(r,w,s)m t|null t=(r+1,w,s)|1<3=(r,w+1,s++"":m:t)
q u c(('*':a):r)=q u a(a:r)
q u c(a@(o:':':_):r)=n a>>q(([o],a):u)c r
q u c r=p"answer: ">>hFlush stdout>>(\i->(r,a(maybe i id$lookup i u)c))`fmap`getLine
a j c|j==c=("correct!",[])|1<3=("incorrect! the answer was "++[head c],["you choose "++j,"the answer was "++c])
main=getArgs>>=readFile.head>>=((0,0,[])&).lines

Molto più a lungo di quanto mi piacerebbe. È impostato wiki, quindi fallo!

Purtroppo, perdiamo 32 personaggi a causa del colore stdout. Altri 38 caratteri potrebbero essere salvati se lo script di test fosse letto da un file fisso denominato "t" anziché specificato nella riga di comando.

Quando eseguito sull'input indicato nella domanda:

& runhaskell 15961-Tester.hs 15961-test.txt 
1. Our site is called Programming Puzzles & Code ________.
A: Debugging
B: Golf
C: Hockey
D: Programming
answer: B
correct!

2. What is the *most* popular tag on our site?
A: [debug]
B: [program]
C: [code-golf]
D: [number]
E: [c++]
answer: C
correct!

3. We are part of the ________ Exchange network.
A: Stack
B: Code
C: Programmer
D: Hockey
answer: B
incorrect! the answer was A

4. Is this the first question?
A: Yes
B: No
answer: B
correct!

5. Is this the last question?
A: Yes
B: No
answer: B
incorrect! the answer was A

overview:
3 correct, 2 incorrect (60%)

3. We are part of the ________ Exchange network.
you choose B: Code
the answer was A: Stack

5. Is this the last question?
you choose B: No
the answer was A: Yes
Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.