<div dir="ltr">Hi,<br><br>In my first message in the list I'm going to ask you to solve this problem or at least help me to solve it by myself:<br><br>We have a list a couples created this way:<br><i>parejas = [(1, 'a'), (1, 'b'), (1, 'c'), (1, 'd'), <br>
               (2, 'a'), (2, 'b'), (2, 'c'),<br>               (3, 'a'), (3, 'b'), (3, 'c'), (3, 'd')]</i><br><br>We want to get all te possible combinations in an ordered way. Good combinations examples are:<br>
<i>1a,2b,3c<br>1a,2b,3d<br>1b,2a,3c</i><br><br>As you note, the numbers or characters cannont be repeated. <br>The objective is to get one possible combination and if the user wants another possible combination he can get it. And if he wants to get bak the previous combiantion is also has to be possible. That's way I said to <b>get all possible combinations in an ordered way.<br>
</b><br>I made a Backtracking algorithm and I get the first result, but I'm not able to get the following result. Any help?<br><br><br>My code, just in case it helps you:<br><i>parejas = [(1, 'a'), (1, 'b'), (1, 'c'), (1, 'd'), <br>
           (2, 'a'), (2, 'b'), (2, 'c'),<br>           (3, 'a'), (3, 'b'), (3, 'c'), (3, 'd')]<br>print parejas<br><br>listasCorrectas = []<br>lista = []<br><br>def numerosDiferentes(lista):<br>
    numeros = []<br>    letras = []<br>    for numero,letra in lista:<br>        numeros.append(numero)<br>        letras.append(letra)<br>    if len(numeros) == len(set(numeros)) and len(letras) == len(set(letras)):<br>        return True<br>
    return False<br>  <br><br>def backTracking(parejas,lista):<br>    if len(lista) == 3 and numerosDiferentes(lista):<br>        listasCorrectas.append(lista)<br>        print 'LISTA CORRECTA',lista<br><br>        return<br>
    <br>    if len(lista) < 2:<br>        lista.append(parejas[0])<br>        print lista<br>        backTracking(parejas[1:],lista)<br>        <br>    while(not numerosDiferentes(lista) and len(lista)>1):<br>        lista = lista[:-1]<br>
    <br>    <br>    lista.append(parejas[0])<br>    print lista<br>    backTracking(parejas[1:],lista)<br><br>backTracking(parejas,lista)</i><br></div>