# Construct a tournament bracket

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.

## Examples

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

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


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

_Lions__
\_Tigers_
_Tigers_/        \
\_Tigers_
_Bears__          /
\_Bears__/
_Oh My__/

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

# 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.

• Do you think there would be any case in which a list input operator would be adcantageous? – ASCII-only Aug 12 '17 at 9:20
• @ASCII-only Well, I could have used it for the ASCII Venn Diagram question... – Neil Aug 12 '17 at 9:39
• :| do you think it's worth implementing? – ASCII-only Aug 12 '17 at 10:06
• @ASCII-only I think you can do ▷vＳ or something for that anyways. – Erik the Outgolfer Aug 12 '17 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:
W=2+max(map(L,c));j=1<<d;J=j/2;D=d+d;d+=1
@r:l[D]=s*W;l[D-1]=s*J
@R(L(c)):
h=l*2*j+j-1;r[h][D]=(u+c[l]+u*W)[:W]
@R(h-J,h+J):r[-~l][~-D]=("/\\"[l<h]+s*abs(h-l-(l<h))).rjust(J)
c=[choice(l)@zip(c[::2],c[1::2])]
@r:print"".join(l)""".replace("@","for l in ")


Try it online!

• You can replace your two-level indents with a singular tab and save three bytes. – Jonathan Frech Sep 19 '17 at 11:43
• 365 bytes. – Jonathan Frech Sep 19 '17 at 11:50
• 364 bytes. – Jonathan Frech Sep 19 '17 at 12:09