#patatoide.py by wouf version 1.0.0
#http://site2wouf.fr/patatoide.php
import random #pour gérer l'ordre aléatoirement
import webbrowser #pour lancer le navigateur
contraintes=list() #la liste des contraintes
quintes=list() #la liste des quintés construite dans la fonction lesquintes()
restes=list() #les quintés filtrés par les contraintes
introhtml="" #pour affichage dans resultats.htm
def lesquintes():
""" Cette fonction construit la liste quintes
variable globale """
for i in range(1,17):
for j in range (i+1,18):
for k in range(j+1,19):
for l in range (k+1,20):
for m in range (l+1,21):
quintes.append({i,j,k,l,m})
def test():
""" On teste le fichier contraintes.txt"""
global introhtml
partant={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}
try:
with open("contraintes.txt" ,"r" ) as f:
#print("Le fichier de contraintes existe et est ouvert" )
texte=f.read()
c=texte.split("\n" )
#print("Il contient " +str(len(c))+" lignes" )
for i in range(len(c)):
if c[i][:8]=="au moins" :
n=c[i][9:].split("dans" )
if int(n[0]) in (1,2,3,4,5) :
m=n[1].split()
me={int(x) for x in m}
ligne=("-" ,int(n[0]),me)
if me<=partant and int(n[0])<=len(me) and ligne not in contraintes:
contraintes.append(ligne)
elif c[i][:7]=="au plus" :
n=c[i][8:].split("dans" )
if int(n[0]) in (0,1,2,3,4,5) :
m=n[1].split()
me={int(x) for x in m}
ligne=("+" ,int(n[0]),me)
if me<=partant and int(n[0])<=len(me)and ligne not in contraintes:
contraintes.append(ligne)
#print()
introhtml+="<p>Nombres de contraintes distinctes reconnues :" +str(len(contraintes))+"</p>"
for c in contraintes:
if c[0]=="-" :
ligne="au moins "
else :
ligne="au plus "
ligne+=str(c[1])+" dans "
for i in sorted(list(c[2])):
ligne += str(i)+" "
#print(ligne)
introhtml+="<p>" +str(ligne)+"</p>"
resultat()
#print("Il reste " ,len(restes), " quintes" )
except IOError:
introhtml+=("<p>Le fichier contraintes.txt est inexistant dans le réperoire de l'application !</p>" )
resultat()
introhtml+="<p>Il reste " +str(len(restes))+" quintes </p>"
def verifie(q,c):
"""q est un set quinte
c est un liste contrainte
la fonction renvoie un booleen"""
if (c[0]=="+" and len(q & c[2])<=int(c[1])) or (c[0]=="-" and len(q & c[2])>=int(c[1])):
return True #le quinté est accepté
else:
return False #le quinté est refusé
def resultat():
""" filtre les quintes avec les contraintes """
for q in quintes:
q=set(q)
bon=True
for c in contraintes:
if not verifie(q,c):
bon=False
if bon:
restes.append(q)
def creehtml():
""" cette fonction crée le fichier html"""
entete="""
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>patatoide from wouf</title>
<style>
ol {counter-reset: i;}
li {
list-style-type: none;
counter-increment: i;
margin-bottom: 3px;
m
}
li:before {
content: counter(i);
padding: 0 20px 2px;
margin-right: 40px;
vertical-align: bottom;
background: #01DF01;
-moz-border-radius: 60px;
border-radius: 60px;
font-weight: bold;
font-size: 0.8em;
color: white;
}
span {
padding: 0 20px 2px;
margin-right: 40px;
vertical-align: bottom;
background: #9AFE2E;
-moz-border-radius: 60px;
border-radius: 60px;
font-size: 0.8em;
color: black;
}
</style>
</head>
<body>
<h1>Patatoide (from Wouf)</h1>
<a href="http://site2wouf.fr/patatoide.php">Le site officiel</a>
"""
entete+=introhtml+"""<p style="margin-left:50px"><ol style="list-style-type: disc;">"""
pied="""
</ol></p></body>
</html>"""
f=open("resultats.htm" ,"+w" )
f.write(entete)
random.shuffle(restes)
for l in restes:
chaine="<li ><span>"
q=list(l)
random.shuffle(q)
for qte in q:
chaine+=" " +str(qte)+" "
chaine+="</span></li>"
f.write(chaine)
f.write(pied)
f.close()
lesquintes()
test()
creehtml()
webbrowser.open("resultats.htm" )