Given an input list of non-empty strings, output an ASCII art representation of a tournament, based on the following drawing rules:

  • The number of strings is guaranteed to be of quantity 2,4,8,16,etc.
  • The first two strings play each other, and the next two play each other, and so on. This is the first round.
  • For each game, choose the winner randomly with equal probability.
  • For the next round, the winner of the first game plays the winner of the second game, the winner of the third game plays the winner of the fourth game, and so on. Subsequent rounds follow the pattern.
  • There is eventually one overall winner.
  • For pretty output (required) the strings must all be prepended and appended with an underscore _.
  • In order for the brackets to line up appropriately, each entry must be padded with _ to all be the same length for that round.
  • You can choose whether the padding is prepended or appended, so long as it's consistent.
  • Instead, you can choose to pre-pad all strings to be the same length, rather than on a per-round basis. Whichever is golfier for your code.

Further Rules

  • Leading or trailing newlines or whitespace are all optional, so long as the characters themselves line up correctly.
  • Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
  • If possible, please include a link to an online testing environment so other people can try out your code!
  • Standard loopholes are forbidden.
  • This is so all usual golfing rules apply, and the shortest code (in bytes) wins.


Example with cities ['Boston', 'New York', 'Charlotte', 'Atlanta', 'St. Paul', 'Chicago', 'Los Angeles', 'Phoenix']:

             \_New York____
_New York____/             \
                            \_New York_
_Charlotte___               /          \
             \_Charlotte___/            \
_Atlanta_____/                           \
                                          \_St. Paul_
_St. Paul____                             /
             \_St. Paul____              /
_Chicago_____/             \            /
                            \_St. Paul_/
_Los Angeles_               /
             \_Los Angeles_/

Example with ['Lions', 'Tigers', 'Bears', 'Oh My']:

_Tigers_/        \
_Bears__          /
_Oh My__/
  • \$\begingroup\$ Related. \$\endgroup\$
    – Okx
    Aug 11, 2017 at 15:22
  • \$\begingroup\$ Does the selection of the winner have to be Mersenne Twister random, or can it be pseudo-random? \$\endgroup\$
    – Zach Gates
    Aug 16, 2017 at 22:57
  • \$\begingroup\$ @ZachGates So long as it's a 50-50 chance between the two "teams," whatever method you want to use is fine. \$\endgroup\$ Aug 17, 2017 at 12:25

2 Answers 2


Charcoal, 92 79 bytes


Try it online! Link is to verbose version of code. Needs a blank line to mark the end of the input. Explanation:


Initialise the variable q. This holds the size of the zig-zags i.e. half the gap between rows.


Read nonblank input lines into the array u. The lines are automatically surrounded by _s as they are read in, although they are not padded yet.


Loop while there are still strings left.


Calculate the width of the largest string in e.


Calculate the gap between rows in d.


For each team, print the padding, print the team, and then move down to the next team.


For every other team, randomly pick between that team or the previous team. (Note that if there is only one team left then this produces an empty list.)


If there are still teams left, draw the zigzags joining them in pairs.


Double the length of the zigzags each time.

  • \$\begingroup\$ Do you think there would be any case in which a list input operator would be adcantageous? \$\endgroup\$
    – ASCII-only
    Aug 12, 2017 at 9:20
  • \$\begingroup\$ @ASCII-only Well, I could have used it for the ASCII Venn Diagram question... \$\endgroup\$
    – Neil
    Aug 12, 2017 at 9:39
  • \$\begingroup\$ :| do you think it's worth implementing? \$\endgroup\$
    – ASCII-only
    Aug 12, 2017 at 10:06
  • \$\begingroup\$ @ASCII-only I think you can do ▷vS or something for that anyways. \$\endgroup\$ Aug 12, 2017 at 17:38

Python 2, 379 364 bytes

exec r"""c=input();from random import*;R,L,d=range,len,0;u,s="_ ";r=[[""]*-~L(c)@R(2*L(c)-1)]
while c:
@r:print"".join(l)""".replace("@","for l in ")

Try it online!

  • \$\begingroup\$ You can replace your two-level indents with a singular tab and save three bytes. \$\endgroup\$ Sep 19, 2017 at 11:43
  • \$\begingroup\$ 365 bytes. \$\endgroup\$ Sep 19, 2017 at 11:50
  • \$\begingroup\$ 364 bytes. \$\endgroup\$ Sep 19, 2017 at 12:09

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.