Stampa una scheda elettorale!


16

Come tutti sapete, oggi è il giorno delle elezioni!

Il tuo compito oggi è quello di stampare una scheda elettorale, dato un input.

Se l'input è Hillary Clinton, stampa:

Hillary Clinton   ===-----===>
Donald Trump      ===     ===>
____________      ===     ===>

Tuttavia, se l'input è Donald Trump, stampa:

Hillary Clinton   ===     ===>
Donald Trump      ===-----===>
____________      ===     ===>

Se è qualcos'altro, scrivilo sulla terza riga:

Hillary Clinton   ===     ===>
Donald Trump      ===     ===>
Oliver Ni         ===-----===>

(Tecnicamente, non ho ancora 18 anni ...)

Ricorda, questo è , quindi vince il codice con il minor numero di byte.


8
Nessuna "nessuna delle opzioni sopra"? :)
Kritixi Lithos

@KritixiLithos Hm, nah ...
Oliver Ni

8
Qualche lunghezza massima sul nome di "qualcos'altro"? (Ci sono 18 caratteri prima del primo segno di uguale nei tuoi esempi)
Link Ng

1
Fa distinzione tra maiuscole e minuscole o insensibile? A giudicare dai casi di test, sto assumendo la sensibilità al momento.
Kevin Cruijssen,

@KritixiLithos, ma sarebbe un rigging del sistema!
OldBunny2800,

Risposte:


6

Gelatina, 55 53 byte

³ẇị⁾- x5⁾ =,”=x3¤j;”>ṭ
ṭ“Gụ©l⁴“%eŻƤ(»”_x12¤ṭQḣ3z⁶ZÇ€Y

Provalo online!

Spiegazione

³ẇị⁾- x5⁾ =,”=x3¤j;”>ṭ   Helper link. Argument: row
³ẇ                       Check if the user's vote is in this row
  ị⁾-                    Take "-" if it was, " " otherwise
      x5                 Take five of that character
        ⁾ =,”=           Take the array [" =", "="]
              x3         Turn it into ["   ===", "==="]
                ¤        Combine the two previous steps into a nilad
                 j       Join the list by the five character string
                  ;”>    Add ">"
                     ṭ   Prepend the original row

ṭ“Gụ©l⁴“%eŻƤ(»”_x12¤ṭQḣ3z⁶ZÇ€Y   Main link. Argument: vote
 “Gụ©l⁴“%eŻƤ(»                   Take the array ["Hillary Clinton", "Donald Trump"]
ṭ                                Add the user's vote to the list
              ”_                 Take "_"
                x12              Take twelve times that
                   ¤             Combine the two previous steps into a nilad
                    ṭ            Add that string to the list
                     Q           Remove duplicates
                      ḣ3         Take the three first items
                        z⁶       Transpose, padding with spaces
                          Z      Transpose back
                           ǀ    Apply the helper to each row
                             Y   Join with newlines

4

Python 2, 127 byte

X=['Hillary Clinton','Donald Trump']
i=input()
X+=[[i],['_'*12]][i in X]
for x in X:print x.ljust(18)+'==='+' -'[i==x]*5+'===>'


2

Java 7, 390 339 335 byte

String c(String s){String h="Hillary Clinton",d="Donald Trump",r=h+"   ===Q===>\n"+d+"      ===X===>\nZ===J===>";boolean H=h.equals(s),D=d.equals(s);for(int i=s.length();i++<18;s+=" ");return r.replace(H?"Q":D?"X":"J","-----").replace(H|D?"Z":"~","____________      ").replaceAll(H?"X|J":D?"Q|J":"Q|X","     ").replace(H|D?"~":"Z",s);}

Codice non testato e test:

Provalo qui.

class M{
  static String c(String s){
    String h = "Hillary Clinton",
           d = "Donald Trump",
           r = h+"   ===Q===>\n"+d+"      ===X===>\nZ===J===>";
    boolean H = h.equals(s),
            D = d.equals(s);
    for(int i = s.length(); i++ < 18; s += " ");
    return r.replace(H?"Q":D?"X":"J", "-----")
            .replace(H|D?"Z":"~", "____________      ")
            .replaceAll(H?"X|J":D?"Q|J":"Q|X", "     ")
            .replace(H|D?"~":"Z", s);
  }

  public static void main(String[] a){
    System.out.println(c("Hillary Clinton"));
    System.out.println();
    System.out.println(c("Donald Trump"));
    System.out.println();
    System.out.println(c("Anyone else?.."));
    System.out.println();
    System.out.println(c("S"));
    System.out.println();
    System.out.println(c("Anyone who is willing to take the job"));
  }
}

Produzione:

Hillary Clinton   ===-----===>
Donald Trump      ===     ===>
____________      ===     ===>

Hillary Clinton   ===     ===>
Donald Trump      ===-----===>
____________      ===     ===>

Hillary Clinton   ===     ===>
Donald Trump      ===     ===>
Anyone else?..    ===-----===>

Hillary Clinton   ===     ===>
Donald Trump      ===     ===>
S                 ===-----===>

Hillary Clinton   ===     ===>
Donald Trump      ===     ===>
Anyone who is willing to take the job===-----===>

2

JavaScript (ES6), 149 byte

s=>['Hillary Clinton','Donald Trump',0].map(S=>((S?S:s||'____________')+p+p+p+p+p).slice(0,18)+`===${!S^S==s?(s=0,'-----'):p}===>`,p='     ').join`
`

dimostrazione


1

V , 104 byte

OHillary Clinton³ ³=µ ³=>YpRDonald Trump   p15r_ñ/^¨á« ᫾©.*î¨.*î©*\1
22|5r-Gdññ3GjéRDk@"Í_/ 
22|5r-

Provalo online!

Questa risposta è troppo confusa e troppo lunga. Immagino sia quello che ottieni quando progetti un linguaggio da golf con un editor di testo.¯\_(ツ)_/¯


aspetta cosa fa O? Sembra che funzioni comei
Conor O'Brien,

@conor È corretto, entrambi entrano in modalità inserimento. L'unica differenza è dove inizia il cursore nel buffer. C'è anche iIaAoOsSRche tutti entrano in modalità insert in un modo o nell'altro
DJMcMayhem

0

Lotto, 210 byte

@set s=%1
@call:l %1 "Hillary Clinton"
@call:l %1 "Donald Trump"
@call:l %1 %s%
@exit/b
:l
@set v=     
@if %1==%2 set v=-----&set s=____________
@set t=%~2                  
@echo %t:~0,18%===%v%===^>

Nota: la riga @set v=ha 5 spazi finali e la riga @set t=%~2ha 18. Accetta input come parametro della riga di comando citato.


0

C #, 266 byte

golfed:

string B(string s){var h="Hilary Clinton".PadRight(17);var d="Donald Trump".PadRight(17);var r="===     ===>\n";var c=r.Replace(" ", "-");var b="____________".PadRight(17);return s==h.Trim()?s.PadRight(17)+c+d+r+b+r:s==d.Trim()?h+r+d+c+b+r:h+r+d+r+s.PadRight(17)+c;}

Ungolfed:

public string B(string s)
{
  var h = "Hilary Clinton".PadRight(17);
  var d = "Donald Trump".PadRight(17);
  var r = "===     ===>\n";
  var c = r.Replace(" ", "-");
  var b = "____________".PadRight(17);
  return s == h.Trim() ? s.PadRight(17) + c + d + r + b + r :
    s == d.Trim() ? h + r + d + c + b + r :
      h + r + d + r + s.PadRight(17) + c;
}

Ho provato a creare un Func per tutti quei PadRight ... Esattamente lo stesso numero di byte ...

test:

var printABallot = new PrintABallot();
Console.WriteLine(printABallot.B("Hilary Clinton"));

Hilary Clinton   ===-----===>
Donald Trump     ===     ===>
____________     ===     ===>


Console.WriteLine(printABallot.B("Donald Trump"));

Hilary Clinton   ===     ===>
Donald Trump     ===-----===>
____________     ===     ===>


Console.WriteLine(printABallot.B("Kanye West"));

Hilary Clinton   ===     ===>
Donald Trump     ===     ===>
Kanye West       ===-----===>


0

Pyth, 76 byte

V{+_tW!}zJ[*\_12"Donald Trump""Hillary Clinton")Jzs[.[Nd18K*\=3*?qzN\-d5K\>
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.