|
|
@ -58,10 +58,12 @@ def cryptarithmeGenerique (s):
|
|
|
|
# print(ListeOperateurs)
|
|
|
|
# print(ListeOperateurs)
|
|
|
|
|
|
|
|
|
|
|
|
# associe à une lettre ses possibilités
|
|
|
|
# associe à une lettre ses possibilités
|
|
|
|
|
|
|
|
|
|
|
|
for i in range(0,len(lettres)):
|
|
|
|
for i in range(0,len(lettres)):
|
|
|
|
|
|
|
|
if(lettres[i] in [ListeMots[y][0] for y in range(0,len(ListeMots))]):
|
|
|
|
|
|
|
|
ListeLettres.append([lettres[i],intvar(1,9, shape=1)])
|
|
|
|
|
|
|
|
else:
|
|
|
|
ListeLettres.append([lettres[i],intvar(0,9, shape=1)])
|
|
|
|
ListeLettres.append([lettres[i],intvar(0,9, shape=1)])
|
|
|
|
# print(ListeLettres)
|
|
|
|
#print(ListeLettres)
|
|
|
|
|
|
|
|
|
|
|
|
# associe pour chaque mot une liste des positions des variables contenu dans ListeLettres
|
|
|
|
# associe pour chaque mot une liste des positions des variables contenu dans ListeLettres
|
|
|
|
|
|
|
|
|
|
|
@ -98,13 +100,14 @@ def cryptarithmeGenerique (s):
|
|
|
|
BigFirstEquationConstraintPart=ConstraintAssemblingList[0]
|
|
|
|
BigFirstEquationConstraintPart=ConstraintAssemblingList[0]
|
|
|
|
for i in range(0,len(ListeOperateurs)):
|
|
|
|
for i in range(0,len(ListeOperateurs)):
|
|
|
|
if(ListeOperateurs[i]=='+'):
|
|
|
|
if(ListeOperateurs[i]=='+'):
|
|
|
|
BigFirstEquationConstraintPart = BigFirstEquationConstraintPart + [ConstraintAssemblingList[i+1]]
|
|
|
|
BigFirstEquationConstraintPart = BigFirstEquationConstraintPart + ConstraintAssemblingList[i+1]
|
|
|
|
if(ListeOperateurs[i]=='-'):
|
|
|
|
if(ListeOperateurs[i]=='-'):
|
|
|
|
BigFirstEquationConstraintPart = BigFirstEquationConstraintPart - [ConstraintAssemblingList[i+1]]
|
|
|
|
BigFirstEquationConstraintPart = BigFirstEquationConstraintPart - ConstraintAssemblingList[i+1]
|
|
|
|
if(ListeOperateurs[i]=='*'):
|
|
|
|
if(ListeOperateurs[i]=='*'):
|
|
|
|
BigFirstEquationConstraintPart = BigFirstEquationConstraintPart * [ConstraintAssemblingList[i+1]]
|
|
|
|
BigFirstEquationConstraintPart = BigFirstEquationConstraintPart * ConstraintAssemblingList[i+1]
|
|
|
|
if(ListeOperateurs[i]=='/'):
|
|
|
|
if(ListeOperateurs[i]=='/'):
|
|
|
|
BigFirstEquationConstraintPart = BigFirstEquationConstraintPart / [ConstraintAssemblingList[i+1]]
|
|
|
|
BigFirstEquationConstraintPart = BigFirstEquationConstraintPart / ConstraintAssemblingList[i+1]
|
|
|
|
|
|
|
|
print(BigFirstEquationConstraintPart)
|
|
|
|
if(ListeOperateurs[i]=='='):
|
|
|
|
if(ListeOperateurs[i]=='='):
|
|
|
|
equalposition=i
|
|
|
|
equalposition=i
|
|
|
|
break
|
|
|
|
break
|
|
|
@ -115,13 +118,14 @@ def cryptarithmeGenerique (s):
|
|
|
|
BigSecondEquationConstraintPart=ConstraintAssemblingList[equalposition+1]
|
|
|
|
BigSecondEquationConstraintPart=ConstraintAssemblingList[equalposition+1]
|
|
|
|
for i in range(equalposition,len(ListeOperateurs)):
|
|
|
|
for i in range(equalposition,len(ListeOperateurs)):
|
|
|
|
if(ListeOperateurs[i]=='+'):
|
|
|
|
if(ListeOperateurs[i]=='+'):
|
|
|
|
BigSecondEquationConstraintPart = BigSecondEquationConstraintPart + [ConstraintAssemblingList[i+1]]
|
|
|
|
BigSecondEquationConstraintPart = BigSecondEquationConstraintPart + ConstraintAssemblingList[i+1]
|
|
|
|
if(ListeOperateurs[i]=='-'):
|
|
|
|
if(ListeOperateurs[i]=='-'):
|
|
|
|
BigSecondEquationConstraintPart = BigSecondEquationConstraintPart - [ConstraintAssemblingList[i+1]]
|
|
|
|
BigSecondEquationConstraintPart = BigSecondEquationConstraintPart + -ConstraintAssemblingList[i+1]
|
|
|
|
if(ListeOperateurs[i]=='*'):
|
|
|
|
if(ListeOperateurs[i]=='*'):
|
|
|
|
BigSecondEquationConstraintPart = BigSecondEquationConstraintPart * [ConstraintAssemblingList[i+1]]
|
|
|
|
BigSecondEquationConstraintPart = BigSecondEquationConstraintPart * ConstraintAssemblingList[i+1]
|
|
|
|
if(ListeOperateurs[i]=='/'):
|
|
|
|
if(ListeOperateurs[i]=='/'):
|
|
|
|
BigSecondEquationConstraintPart = BigSecondEquationConstraintPart / [ConstraintAssemblingList[i+1]]
|
|
|
|
BigSecondEquationConstraintPart = BigSecondEquationConstraintPart / ConstraintAssemblingList[i+1]
|
|
|
|
|
|
|
|
print(BigSecondEquationConstraintPart)
|
|
|
|
# print(BigSecondEquationConstraintPart)
|
|
|
|
# print(BigSecondEquationConstraintPart)
|
|
|
|
|
|
|
|
|
|
|
|
# Création du model et de ses contraintes
|
|
|
|
# Création du model et de ses contraintes
|
|
|
@ -149,6 +153,9 @@ def cryptarithmeGenerique (s):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
print("No solution found")
|
|
|
|
print("No solution found")
|
|
|
|
|
|
|
|
|
|
|
|
cryptarithmeGenerique("SEND + MORE = MONEY");
|
|
|
|
cryptarithmeGenerique("SEND + MORE = MONEY")
|
|
|
|
cryptarithmeGenerique("HUIT + HUIT = SEIZE");
|
|
|
|
cryptarithmeGenerique("HUIT + HUIT = SEIZE")
|
|
|
|
cryptarithmeGenerique("UN + UN + NEUF = ONZE");
|
|
|
|
cryptarithmeGenerique("UN + UN + NEUF = ONZE")
|
|
|
|
|
|
|
|
cryptarithmeGenerique("UN + TROIS - NEUF = ONZE")
|
|
|
|
|
|
|
|
cryptarithmeGenerique("UN * UN = ONZE")
|
|
|
|
|
|
|
|
cryptarithmeGenerique("UNN / UN = UN")
|