Bonjour,

Je donnerai des détails sur la finalité du résultat, quand cela sera possible :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
import random
 
class View(object):
    s=[]
    mid=0
    nine=3
    for i in range(3000):
        for j in range(3):
            u=random.randint(1, 13)
            v=random.randint(1, 13)
            w=random.randint(1, 13)
        cond1 = (u!=nine and v!=nine and w!=nine)
        cond2 = (u!=v and v!=w and w!=u)
        cond3 =  (u+v+w == 21)
        if cond1 and cond2 and cond3 == True :
            list = u,v,w
            #print list,sum(list)
            up=max(list)
            down=min(list)
            mid=21-up-down
            s.append((up,mid,down))
    klist=set(s)
    kklist = sorted(klist, reverse=True)  
 
for i in range(5):
    ex=random.randint(1, 1000)
    table='kk'+str(ex)
    tab= View()
    view=tab.kklist
    print table, view
Dans cette partie, 5 instances de View sont affichés
Ce qui manque pour la suite et que les 5 view sont jetables

view va suivre le même algo avec des instance différentes
Les triplets de view sont éliminés jusqu'à un test
Quand ce test est négatif, il faut régénérer le view, et recommence de nouveaux calculs

Question : Comment détruire le view précédent et utiliser le view suivant ?

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
while(len(view) > 2):
 
    if doublon > 0 :
        print 'RAZ DOUBLON :'
        ex=random.randint(1, 1000)
        table='kk'+str(ex)
        print table
        table= View()
        print table
        view=table.kklist
        print view
        resu=[]
        tot=13
 
# etc ...
Le corps principal est une boucle while
Quand une condition ( doublon ) est vrai, il faut régénérer le view

Le test if doublon ne fonctionne pas avec la classe View ci-dessus

Pouvez vous apporter vos conseils ?
Cdlt