How to make this code work better (list of combinations)?

0
import random


def ordenar(inputx):
    inputx = list(inputx)
    inputx = sorted(inputx, key=int)
    return inputx


def get_numbers(totall):
    return random.sample(numeros, totall)


numeros = [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]

all_jogos = []
maximo_repetido = 9

vezes = 0


while True:
    numbers = get_numbers(15)
    for i in all_jogos:
        total_repetido = len(set(numbers).intersection(i))
        if total_repetido <= maximo_repetido:
            vezes += 1
        else:
            vezes = 0
            break
    if vezes >= len(all_jogos):
        all_jogos.append(numbers)
        print("%s," % ordenar(numbers))

Basically my intention is to generate lists of 15 numbers, so that there are no more than 9 numbers repeated between them (variable maximum_repeat ), generating as many lists as possible. The comparison is made with all lists contained in all_games , which grows with each loop as long as the condition is accepted.

The problem is that all possible results can never occur, since validation / comparison is only done after generating 15 random numbers.

How do you make the condition / validation / comparison to be done at the moment you are going to generate the numbers, forcing you to search only for the possible results?

    
asked by anonymous 02.06.2018 / 02:41

0 answers