Commit initial
|
@ -0,0 +1,185 @@
|
|||
from random import *
|
||||
|
||||
def proba2D6(seuil):
|
||||
liste = [1.0/36,2.0/36,3.0/36,4.0/36,5.0/36,6.0/36,5.0/36,4.0/36,3.0/36,2.0/36,1.0/36]
|
||||
try:
|
||||
index=seuil.index('-')
|
||||
bas=int(seuil[0:index])
|
||||
haut=int(seuil[index+1:])
|
||||
except:
|
||||
bas=haut=int(seuil)
|
||||
return sum(liste[bas-2:haut-1])
|
||||
|
||||
def getseuil(seuil):
|
||||
try:
|
||||
index=seuil.index('-')
|
||||
bas=int(seuil[0:index])
|
||||
haut=int(seuil[index+1:])
|
||||
except:
|
||||
bas=haut=int(seuil)
|
||||
return (bas,haut)
|
||||
|
||||
def lance():
|
||||
return randint(1,6)+randint(1,6)
|
||||
|
||||
def getresult(de,liste):
|
||||
for seuil,result in liste.iteritems():
|
||||
seuils = getseuil(seuil)
|
||||
if de>=seuils[0] and de<=seuils[1]:
|
||||
return result
|
||||
|
||||
def makedict():
|
||||
dict = {}
|
||||
for i in range(2,13):
|
||||
for j in range(i+1,13):
|
||||
seuil=str(i)+'-'+str(j)
|
||||
proba=round(proba2D6(seuil),3)
|
||||
#print "%d-%d : %s %f" % (i,j,seuil,proba)
|
||||
if dict.has_key(proba):
|
||||
dict[proba].append(seuil)
|
||||
else:
|
||||
dict[proba]=[seuil]
|
||||
for i in range(2,13):
|
||||
seuil=str(i)
|
||||
proba=round(proba2D6(seuil),3)
|
||||
#print "%d-%d : %s %f" % (i,j,seuil,proba)
|
||||
if dict.has_key(proba):
|
||||
dict[proba].append(seuil)
|
||||
else:
|
||||
dict[proba]=[seuil]
|
||||
dict[0]=['0']
|
||||
return dict
|
||||
|
||||
def mini(liste):
|
||||
result=[]
|
||||
for i in range(len(liste)):
|
||||
result.append(liste[i][1])
|
||||
return result
|
||||
|
||||
def closeast(values,liste):
|
||||
final = []
|
||||
for i in range(len(values)):
|
||||
prop = []
|
||||
for j in range(len(liste)):
|
||||
prop.append((abs(values[i]-liste[j]),liste[j]))
|
||||
final.append(sorted(prop))
|
||||
return final
|
||||
|
||||
def tester(liste):
|
||||
somme=sum(liste)
|
||||
if abs(somme-1.0)>0.001:
|
||||
print "ERREUUUUUUR : %f" % (somme)
|
||||
exit()
|
||||
|
||||
def least(liste,indices):
|
||||
mini=1
|
||||
column=-1
|
||||
for i in range(len(liste)):
|
||||
if liste[i][indices[i]][0]<mini:
|
||||
mini=liste[i][indices[i]][0]
|
||||
column=i
|
||||
return column
|
||||
|
||||
def testlist(liste,indices):
|
||||
sum=0
|
||||
for i in range(len(liste)):
|
||||
sum=liste[i][indices[i]][1]+sum
|
||||
return sum
|
||||
|
||||
def testdicelist(liste):
|
||||
full=[0]*11
|
||||
for i in range(len(liste)):
|
||||
if liste[i]!='0':
|
||||
seuils=getseuil(liste[i])
|
||||
#print seuils
|
||||
for j in range(seuils[0]-2,seuils[1]-1):
|
||||
if full[j]==0:
|
||||
full[j]=1
|
||||
else:
|
||||
return False
|
||||
#print full
|
||||
if sum(full)==11:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def returnlist(liste,indices):
|
||||
list=[]
|
||||
for i in range(len(liste)):
|
||||
list.append(liste[i][indices[i]][1])
|
||||
return list
|
||||
|
||||
def closeastlist(liste,resultats):
|
||||
indices=[0]*len(liste)
|
||||
near=closeast(liste,resultats)
|
||||
#print near
|
||||
while abs(testlist(near,indices)-1.0)>0.0011:
|
||||
print "Somme:%f, proche:%d" % (abs(testlist(near,indices)-1.0),least(near,indices))
|
||||
print indices
|
||||
retenue=True
|
||||
for i in range(0,len(indices)):
|
||||
if retenue:
|
||||
indices[i]=indices[i]+1
|
||||
if indices[i]==len(resultats):
|
||||
indices[i]=0
|
||||
retenue=True
|
||||
else:
|
||||
break
|
||||
if len(resultats) in indices:
|
||||
print "impossible !"
|
||||
exit()
|
||||
#print "Somme:%f, proche:%d" % (testlist(near,indices),least(near,indices))
|
||||
list=returnlist(near,indices)
|
||||
return list
|
||||
|
||||
def brutlist(liste,dict):
|
||||
tester(liste)
|
||||
resultats=list(dict)
|
||||
resultats.sort()
|
||||
#print resultats
|
||||
liste=closeastlist(liste,resultats)
|
||||
print "Approche probabiliste"
|
||||
print liste
|
||||
proba=[]
|
||||
for i in range(len(liste)):
|
||||
proba.append(dict[liste[i]])
|
||||
print "Arrangements possibles"
|
||||
print proba
|
||||
#raw_input("...")
|
||||
indices=[0]*len(liste)
|
||||
test=[]
|
||||
for i in range(len(liste)):
|
||||
test.append(proba[i][indices[i]])
|
||||
print "Solutions"
|
||||
while True:
|
||||
if testdicelist(test):
|
||||
print test
|
||||
retenue=True
|
||||
for i in range(0,len(indices)):
|
||||
if retenue:
|
||||
if i==len(indices)-1:
|
||||
print "fin des solutions"
|
||||
exit()
|
||||
indices[i]=indices[i]+1
|
||||
if indices[i]==len(proba[i]):
|
||||
indices[i]=0
|
||||
retenue=True
|
||||
else:
|
||||
break
|
||||
test=[]
|
||||
for i in range(len(liste)):
|
||||
test.append(proba[i][indices[i]])
|
||||
#print test
|
||||
|
||||
|
||||
import sys
|
||||
if len(sys.argv)<2:
|
||||
print "Manque argument: liste a atteindre"
|
||||
exit()
|
||||
liste= sys.argv[1].split(",")
|
||||
for i in range(len(liste)):
|
||||
liste[i]=float(liste[i])
|
||||
dict=makedict()
|
||||
#print dict
|
||||
essai=brutlist(liste,dict)
|
||||
print essai
|
After Width: | Height: | Size: 1.4 KiB |
|
@ -0,0 +1,124 @@
|
|||
from random import *
|
||||
|
||||
def proba2D6(seuil):
|
||||
liste = [1.0/36,2.0/36,3.0/36,4.0/36,5.0/36,6.0/36,5.0/36,4.0/36,3.0/36,2.0/36,1.0/36]
|
||||
try:
|
||||
index=seuil.index('-')
|
||||
bas=int(seuil[0:index])
|
||||
haut=int(seuil[index+1:])
|
||||
except:
|
||||
bas=haut=int(seuil)
|
||||
return sum(liste[bas-2:haut-1])
|
||||
|
||||
def getseuil(seuil):
|
||||
try:
|
||||
index=seuil.index('-')
|
||||
bas=int(seuil[0:index])
|
||||
haut=int(seuil[index+1:])
|
||||
except:
|
||||
bas=haut=int(seuil)
|
||||
return (bas,haut)
|
||||
|
||||
def testdicelist(liste):
|
||||
full=[0]*11
|
||||
for i in range(len(liste)):
|
||||
if liste[i]!='0':
|
||||
seuils=getseuil(liste[i])
|
||||
#print seuils
|
||||
for j in range(seuils[0]-2,seuils[1]-1):
|
||||
if full[j]==0:
|
||||
full[j]=1
|
||||
else:
|
||||
return False
|
||||
#print full
|
||||
if sum(full)==11:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def lance():
|
||||
return randint(1,6)+randint(1,6)
|
||||
|
||||
def getresult(de,liste):
|
||||
for seuil,result in liste.iteritems():
|
||||
seuils = getseuil(seuil)
|
||||
if de>=seuils[0] and de<=seuils[1]:
|
||||
return result
|
||||
|
||||
lancer=1000000
|
||||
prob=0
|
||||
print "Evaluations statistiques sur %d lances" % lancer
|
||||
etoiles={'2':'Naine Brune','6-7':'Naine Rouge','8-9':'Naine Jaune','3-4':'Geante rouge','5':'Geante bleue','11':'Super geante R','12':'Etoile double','10':'Trou noir'}
|
||||
types={
|
||||
'Naine Brune': {'2':'Tellurique','10-12':'Gazeuse','5-7':'Gelee','4':'Oceanique','8-9':'Sterile','3':'Lave','0':'Vivante'},
|
||||
'Naine Rouge': {'11':'Tellurique','9-10':'Gazeuse','6-7':'Gelee','8':'Oceanique','2-4':'Sterile','5':'Lave','12':'Vivante'},
|
||||
'Naine Jaune': {'7-8':'Tellurique','10':'Gazeuse','9':'Gelee','5-6':'Oceanique','2':'Sterile','11-12':'Lave','3-4':'Vivante'},
|
||||
'Geante rouge': {'11-12':'Tellurique','5-6':'Gazeuse','2':'Gelee','4':'Oceanique','9-10':'Sterile','7-8':'Lave','3':'Vivante'},
|
||||
'Geante bleue': {'12':'Tellurique','5':'Gazeuse','0':'Gelee','4':'Oceanique','6-8':'Sterile','9-11':'Lave','2-3':'Vivante'},
|
||||
'Super geante R': {'11-12':'Tellurique','4-5':'Gazeuse','0':'Gelee','0':'Oceanique','2-3':'Sterile','6-10':'Lave','0':'Vivante'},
|
||||
'Etoile double': {'2-4':'Tellurique','5-6':'Gazeuse','10':'Gelee','0':'Oceanique','7-9':'Sterile','0':'Lave','11-12':'Vivante'}}
|
||||
|
||||
nombres={
|
||||
'Naine Brune': {'5-8':1,'9-11':2,'4':3,'3':4,'2':5,'12':6},
|
||||
'Naine Rouge': {'11-12':1,'5-6':2,'7-8':3,'9-10':4,'3-4':5,'2':6},
|
||||
'Naine Jaune': {'12':1,'2-3':2,'4-5':3,'6-7':4,'8-9':5,'10-11':6},
|
||||
'Geante rouge': {'8-9':1,'6-7':2,'2-5':3,'10-11':4,'12':5,'0':6},
|
||||
'Geante bleue': {'6-7':1,'8-10':2,'2-5':3,'11-12':4,'0':5,'0':6},
|
||||
'Super geante R': {'7-11':1,'2-6':2,'12':3,'0':4,'0':5,'0':6},
|
||||
'Etoile double': {'2-3':1,'4-5':2,'6-7':3,'8-9':4,'10-11':5,'12':6}}
|
||||
probabilite={}
|
||||
allplanet=0
|
||||
print "Verification des intervals..."
|
||||
print "Recapitulatif \t %s" % (testdicelist(list(etoiles)))
|
||||
for type in list(types):
|
||||
print "%s \t %s : %s" % (type,testdicelist(list(types[type])),testdicelist(list(nombres[type])))
|
||||
raw_input("...")
|
||||
|
||||
for i in range(lancer):
|
||||
de=lance()
|
||||
result_etoile=getresult(de,etoiles)
|
||||
print "**************** \nDetermination etoile...%d : %s" % (de,result_etoile)
|
||||
prob="1."+result_etoile;
|
||||
if probabilite.has_key(prob):
|
||||
value=probabilite[prob]
|
||||
probabilite[prob]=value+1
|
||||
else:
|
||||
probabilite[prob]=1
|
||||
if result_etoile!="Trou noir":
|
||||
de=lance()
|
||||
result_nombre=getresult(de,nombres[result_etoile])
|
||||
print "Determination taille...%d : %s" % (de,result_nombre)
|
||||
prob="2."+str(result_nombre);
|
||||
if probabilite.has_key(prob):
|
||||
value=probabilite[prob]
|
||||
probabilite[prob]=value+1
|
||||
else:
|
||||
probabilite[prob]=1
|
||||
allplanet=allplanet+result_nombre
|
||||
for j in range(result_nombre):
|
||||
de=lance()
|
||||
result_type=getresult(de,types[result_etoile])
|
||||
print " Determination type...%d : %s" % (de,result_type)
|
||||
prob="3."+result_type;
|
||||
if probabilite.has_key(prob):
|
||||
value=probabilite[prob]
|
||||
probabilite[prob]=value+1
|
||||
else:
|
||||
probabilite[prob]=1
|
||||
resultats=list(probabilite)
|
||||
resultats.sort()
|
||||
print resultats
|
||||
for i in range(len(resultats)):
|
||||
if resultats[i][0]=='3':
|
||||
proba=probabilite[resultats[i]]/float(allplanet)*100.0;
|
||||
else:
|
||||
proba=probabilite[resultats[i]]/float(lancer)*100.0;
|
||||
print " Caracteristique %s : %d, %f" % (resultats[i],probabilite[resultats[i]],proba)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 5.0 MiB |
After Width: | Height: | Size: 681 KiB |
After Width: | Height: | Size: 2.6 MiB |
After Width: | Height: | Size: 179 KiB |
After Width: | Height: | Size: 109 KiB |
After Width: | Height: | Size: 349 KiB |
After Width: | Height: | Size: 188 KiB |
After Width: | Height: | Size: 1.0 MiB |
After Width: | Height: | Size: 899 KiB |
After Width: | Height: | Size: 148 KiB |
After Width: | Height: | Size: 1.0 MiB |
After Width: | Height: | Size: 534 KiB |
After Width: | Height: | Size: 168 KiB |
After Width: | Height: | Size: 4.6 MiB |
After Width: | Height: | Size: 4.6 MiB |
After Width: | Height: | Size: 4.1 MiB |
After Width: | Height: | Size: 2.8 MiB |
After Width: | Height: | Size: 4.2 MiB |
After Width: | Height: | Size: 291 KiB |