Created
September 12, 2016 06:38
-
-
Save petrikoz/c6a716aa9f9ab3e0aacded326333ec62 to your computer and use it in GitHub Desktop.
Гусятник в туристических группах
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Случайное распрделение участников для "гуся". | |
На выходе получаем спиоск пар "дарящий - получающий": | |
[(5, 4), (3, 2), (4, 7), (2, 1), (6, 3), (7, 5), (1, 6)] | |
Нужно просто задать количество участников в группе. | |
И потом просто распределить их в какую-нить таблицу. Например: | |
1 -> Илья | |
2 -> Маша | |
3 -> Петя | |
4 -> Дима | |
5 -> Слава | |
6 -> Коля | |
7 -> Аня | |
И из результата выше получаем, что: | |
(5, 4): Слава -> дарит гуся -> Диме | |
(3, 2): Петя -> дарит гуся -> Маше | |
(4, 7): Дима -> дарит гуся -> Ане | |
(2, 1): Маша -> дарит гуся -> Илье | |
(6, 3): Коля -> дарит гуся -> Пете | |
(7, 5): Аня -> дарит гуся -> Славе | |
(1, 6): Илья -> дарит гуся -> Коле | |
Для добавления интриги нужно, чтобы таблицу с приязкой чюдей к цифрам делал | |
человек не присутствующий в таблице. | |
''' | |
import random | |
count = 7 | |
first = set() | |
second = set() | |
couples = set() | |
def u_choice(stop, choices, user=None): | |
_user = random.randint(1, stop) | |
if _user != user and _user not in choices: | |
choices.add(_user) | |
return _user, choices | |
return u_choice(stop, choices, user) | |
while len(couples) < count: | |
user1, choices = u_choice(count, first) | |
user2, choices = u_choice(count, second, user1) | |
couples.add((user1, user2)) | |
print('Couples: ', couples) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment