-
Notifications
You must be signed in to change notification settings - Fork 7
/
groups_selection.py
75 lines (67 loc) · 1.55 KB
/
groups_selection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#! /usr/bin/python3
import random
DATA = [
"Helio",
"Alexandre",
"Maria",
"Caio",
"Léo",
"Laura",
"Juliana",
"Marcelo",
"Pedro",
"Luiz",
"Eliana",
"elaine",
"Andréia",
"André",
"Júlia"
]
def get_random(total):
return random.randint(0, total - 1)
people = len(DATA)
months = people - 1
print("People=%d" % people)
print("Months=%d" % months)
combinations = []
counter = {}
# matrix
for y in range(0,people):
row = []
for x in range(0, people):
if x == y:
row.append(x)
else:
row.append(None)
#print(row)
combinations.append(row)
counter[y] = 0
for y in range(0,people):
for x in range(0,people):
if x == y:
continue
while True:
dice = get_random(people)
if not dice in combinations[y]:
if counter[dice] >= months:
continue
else:
counter[dice] += 1
combinations[y][x] = dice
break
row = ",".join(map(str,combinations[y]))
#print("%d: %s" % (y, row))
#print(counter)
groups = {}
for y in range(0, people):
for x in range(0, people):
if x == y:
continue
value = combinations[x][y]
#print("%d,%d=%d" % (x,y,value))
if not value in groups:
groups[value] = []
groups[value].append("%s and %s" % (DATA[x], DATA[y]))
for month in groups.keys():
teams = ",".join(groups[month])
print("%d) %s" % (month, teams))