Vassillia a écrit:Tu as bien eu raison de ne pas t’embêter surtout que tu ne cherchais que les cas n=3 ou n=4
# Fabrique la liste des sous-suites de A et B
def Liste(A,B) :
L=['']
for i in range (len(A)-1):
if A[:i+1]==B[:i+1] :
L.append(A[:i+1])
else :
L.append(A[:i+1])
L.append(B[:i+1])
return L
import numpy as np
def Prob(A,B) :
L=Liste(A,B)
l=len(L)
Q=np.zeros((l,l)) ; R=np.zeros((l,2))
R[l-2,0]=1/2 ; R[l-1,1]=1/2
for T in L :
TP=T+'P'
if TP != A and TP != B :
retour=-1;vide=1
while retour != len(T):
retour = retour + 1
if TP[retour:]in L:
Q[L.index(T),L.index(TP[retour:])]=1/2
retour = len(T)
vide=0
if vide==1 :Q[L.index(T),0]=1/2
TF=T+'F'
if TF != A and TF != B :
retour=-1;vide=1
while retour != len(T):
retour = retour + 1
if TF[retour:]in L:
Q[L.index(T),L.index(TF[retour:])]=1/2
retour = len(T)
vide=0
if vide==1 :Q[L.index(T),0]=1/2
# Vecteur initial
init=np.array([1]+(l-1)*[0])
# Matrice fondamentale
N=np.linalg.inv(np.identity(l)-Q)
# Retour des probabilités de victoire pour A et B
return init.dot(N).dot(R)
def Champion(A) :
L=LTPF(len(A))
p=0.5
for B in L :
if B!= A :
q=Prob(A,B)[1]
if q>p:
p=q
resultat=B
print("Contre {0} : {1}, avec {2:.1%} de chances de gagner"\
.format(A,resultat,p))
Utilisateurs parcourant ce forum : Aucun utilisateur enregistré et 9 invités
Tu pars déja ?
Identification
Pas encore inscrit ?
Ou identifiez-vous :