Skip to content

Instantly share code, notes, and snippets.

@tspycher
Last active May 12, 2016 11:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tspycher/bcd55285cf9b1f6afe0c20ec8660eb71 to your computer and use it in GitHub Desktop.
Save tspycher/bcd55285cf9b1f6afe0c20ec8660eb71 to your computer and use it in GitHub Desktop.
A fellow just asked me how simple it would be to create the most simple tournament application. this is what came out in a couple of minutes.
import random
import math
teamof = 2
def teams(people):
teams = []
for i in range(len(people) / teamof):
team = []
for i in range(teamof):
p = random.choice(people)
people.remove(p)
team.append(p)
teams.append("-".join(team).upper())
return teams
def play(teams):
while True:
if not teams or not len(teams) >= teamof:
break
round = []
for i in range(int(math.ceil(len(teams) / 2))):
a = random.choice(teams)
teams.remove(a)
b = random.choice(teams)
teams.remove(b)
round.append([a,b])
for battle in round:
won = random.choice(battle)
print "battle %s vs %s and won %s" % (battle[0], battle[1], won)
teams.append(won)
for y in range(100):
people = ["Tom", "Sam","Mike", "Anna","Sandra", "John","Peter", "Nicole","Lucy", "Jenny","Phil", "Michael", "Carolina", "Frank"]
if len(people) % teamof:
print "Not a divided by %d number of people" % teamof
exit(9)
_teams = teams(people)
play( _teams )
print "Winner is: %s" % _teams[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment