16
\$\begingroup\$

As you all know, today is election day!

Your task today is to print out a ballot, given an input.

If the input is Hillary Clinton, print:

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

However, if the input is Donald Trump, print:

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

If it is something else, write it on the third line:

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

(Technically, I'm not 18 yet...)

Remember, this is , so the code with the fewest bytes wins.

\$\endgroup\$
5
  • 8
    \$\begingroup\$ No "none of the above option"? :) \$\endgroup\$
    – user41805
    Commented Nov 9, 2016 at 5:27
  • \$\begingroup\$ @KritixiLithos Hm, nah... \$\endgroup\$
    – Oliver Ni
    Commented Nov 9, 2016 at 5:28
  • 8
    \$\begingroup\$ Any max length on the name of "something else"? (There are 18 characters before the first equal sign in your examples) \$\endgroup\$
    – Link Ng
    Commented Nov 9, 2016 at 6:49
  • 1
    \$\begingroup\$ Is it case sensitive or insensitive? Judging by the test cases I'm assuming sensitive at the moment. \$\endgroup\$ Commented Nov 9, 2016 at 9:37
  • \$\begingroup\$ @KritixiLithos but that would be rigging the system! \$\endgroup\$
    – AAM111
    Commented Nov 9, 2016 at 21:18

10 Answers 10

6
\$\begingroup\$

Jelly, 55 53 bytes

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

Try it online!

Explanation

³ẇị⁾- 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
\$\endgroup\$
4
\$\begingroup\$

Python 2, 127 bytes

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

05AB1E, 74 59 57 bytes

Uses CP-1252 encoding.

”ŽÏaryµÍ””¹Ñ Trump”I'_12×)Ù3£vyð18yg-ׄ -¹yQè5×'=3×.ø'>J,

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Java 7, 390 339 335 bytes

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

Ungolfed & test code:

Try it here.

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

Output:

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===-----===>
\$\endgroup\$
2
\$\begingroup\$

JavaScript (ES6), 149 bytes

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

Demo

let f =

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

console.log(f('Hillary Clinton'))
console.log(f('Donald Trump'))
console.log(f('Obi-Wan Kenobi'))

\$\endgroup\$
1
\$\begingroup\$

V, 104 bytes

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

Try it online!

This answer is way too hacky, and way too long. I guess that's what you get when you design a golfing-language off of a text-editor. ¯\_(ツ)_/¯

\$\endgroup\$
2
  • \$\begingroup\$ wait what does O do? It looks like it functions like i \$\endgroup\$ Commented Nov 11, 2016 at 1:53
  • \$\begingroup\$ @conor That's correct, they both enter insert mode. The only difference is where in the buffer the cursor starts. There's also iIaAoOsSR that all enter insert mode in some way or another \$\endgroup\$
    – DJMcMayhem
    Commented Nov 11, 2016 at 1:56
0
\$\begingroup\$

Batch, 210 bytes

@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%===^>

Note: the line @set v= has 5 trailing spaces, and the line @set t=%~2 has 18. Accepts input as a quoted command-line parameter.

\$\endgroup\$
0
\$\begingroup\$

C#, 266 Bytes

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

Tried to create a Func for all those PadRights...Exactly the same byte count...

Testing:

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       ===-----===>
\$\endgroup\$
0
\$\begingroup\$

Python 3.6, 132 bytes

i=input()
s=['Hillary Clinton','Donald Trump','_'*12]
if x not in s:s[2]=i
for k in s:print(f'{k:18}==={" -"[k==i]*5}===>')

Uses 3.6's new f-strings.

\$\endgroup\$
0
\$\begingroup\$

Pyth, 76 bytes

V{+_tW!}zJ[*\_12"Donald Trump""Hillary Clinton")Jzs[.[Nd18K*\=3*?qzN\-d5K\>
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.