|
|
|
@ -91,37 +91,37 @@ def cryptarithmeGenerique (s):
|
|
|
|
|
# creation des parties de la contrainte globale du cryptarithme
|
|
|
|
|
|
|
|
|
|
for i in range(0,len(ListeMots)):
|
|
|
|
|
ConstraintAssemblingList.append(sum([ListeLettres[ListePositions[i][y]][1]*10**(len(ListeMots[i])-y) for y in range(0,len(ListeMots[i]))]))
|
|
|
|
|
ConstraintAssemblingList.append(sum([ListeLettres[ListePositions[i][y]][1]*10**(len(ListeMots[i])-y-1) for y in range(0,len(ListeMots[i]))]))
|
|
|
|
|
# print(ConstraintAssemblingList)
|
|
|
|
|
|
|
|
|
|
# assemblage des parties de la contrainte globale du cryptarithme avant le =
|
|
|
|
|
|
|
|
|
|
BigFirstEquationConstraintPart=ConstraintAssemblingList[0]
|
|
|
|
|
for i in range(0,len(ListeOperateurs)):
|
|
|
|
|
if(ListeOperateurs[i]=='+'):
|
|
|
|
|
BigFirstEquationConstraintPart.append(ConstraintAssemblingList[i]+ConstraintAssemblingList[i+1])
|
|
|
|
|
BigFirstEquationConstraintPart = BigFirstEquationConstraintPart + [ConstraintAssemblingList[i+1]]
|
|
|
|
|
if(ListeOperateurs[i]=='-'):
|
|
|
|
|
BigFirstEquationConstraintPart.append(ConstraintAssemblingList[i]-ConstraintAssemblingList[i+1])
|
|
|
|
|
BigFirstEquationConstraintPart = BigFirstEquationConstraintPart - [ConstraintAssemblingList[i+1]]
|
|
|
|
|
if(ListeOperateurs[i]=='*'):
|
|
|
|
|
BigFirstEquationConstraintPart.append(ConstraintAssemblingList[i]*ConstraintAssemblingList[i+1])
|
|
|
|
|
BigFirstEquationConstraintPart = BigFirstEquationConstraintPart * [ConstraintAssemblingList[i+1]]
|
|
|
|
|
if(ListeOperateurs[i]=='/'):
|
|
|
|
|
BigFirstEquationConstraintPart.append(ConstraintAssemblingList[i]/ConstraintAssemblingList[i+1])
|
|
|
|
|
BigFirstEquationConstraintPart = BigFirstEquationConstraintPart / [ConstraintAssemblingList[i+1]]
|
|
|
|
|
if(ListeOperateurs[i]=='='):
|
|
|
|
|
equalposition=i
|
|
|
|
|
break
|
|
|
|
|
# print(BigFirstEquationConstraintPart[0])
|
|
|
|
|
# print(BigFirstEquationConstraintPart)
|
|
|
|
|
|
|
|
|
|
# assemblage des parties de la contrainte globale du cryptarithme après le =
|
|
|
|
|
|
|
|
|
|
BigSecondEquationConstraintPart=ConstraintAssemblingList[equalposition+1]
|
|
|
|
|
for i in range(equalposition,len(ListeOperateurs)):
|
|
|
|
|
if(ListeOperateurs[i]=='+'):
|
|
|
|
|
BigSecondEquationConstraintPart.append(ConstraintAssemblingList[i]+ConstraintAssemblingList[i+1])
|
|
|
|
|
BigSecondEquationConstraintPart = BigSecondEquationConstraintPart + [ConstraintAssemblingList[i+1]]
|
|
|
|
|
if(ListeOperateurs[i]=='-'):
|
|
|
|
|
BigSecondEquationConstraintPart.append(ConstraintAssemblingList[i]-ConstraintAssemblingList[i+1])
|
|
|
|
|
BigSecondEquationConstraintPart = BigSecondEquationConstraintPart - [ConstraintAssemblingList[i+1]]
|
|
|
|
|
if(ListeOperateurs[i]=='*'):
|
|
|
|
|
BigSecondEquationConstraintPart.append(ConstraintAssemblingList[i]*ConstraintAssemblingList[i+1])
|
|
|
|
|
BigSecondEquationConstraintPart = BigSecondEquationConstraintPart * [ConstraintAssemblingList[i+1]]
|
|
|
|
|
if(ListeOperateurs[i]=='/'):
|
|
|
|
|
BigSecondEquationConstraintPart.append(ConstraintAssemblingList[i]/ConstraintAssemblingList[i+1])
|
|
|
|
|
BigSecondEquationConstraintPart = BigSecondEquationConstraintPart / [ConstraintAssemblingList[i+1]]
|
|
|
|
|
# print(BigSecondEquationConstraintPart)
|
|
|
|
|
|
|
|
|
|
# Création du model et de ses contraintes
|
|
|
|
@ -130,7 +130,7 @@ def cryptarithmeGenerique (s):
|
|
|
|
|
|
|
|
|
|
# Mise en place de la contrainte globale
|
|
|
|
|
|
|
|
|
|
model += (BigFirstEquationConstraintPart[0] == BigSecondEquationConstraintPart)
|
|
|
|
|
model += (BigFirstEquationConstraintPart == BigSecondEquationConstraintPart)
|
|
|
|
|
|
|
|
|
|
# Mise en place de la contrainte où toutes les lettres sont différentes
|
|
|
|
|
|
|
|
|
@ -151,4 +151,4 @@ def cryptarithmeGenerique (s):
|
|
|
|
|
|
|
|
|
|
cryptarithmeGenerique("SEND + MORE = MONEY");
|
|
|
|
|
cryptarithmeGenerique("HUIT + HUIT = SEIZE");
|
|
|
|
|
# cryptarithmeGenerique("UN + UN + NEUF = ONZE");
|
|
|
|
|
cryptarithmeGenerique("UN + UN + NEUF = ONZE");
|