Deplacement de WEB
continuous-integration/drone/push Build is failing
Details
@ -1,161 +0,0 @@
|
||||
# file cryptarithme.py
|
||||
# brief solution générique des cryptarithme
|
||||
# author Johan Lachenal
|
||||
# date 17 Octobre 2022
|
||||
# ce fichier contient l'algorithme générique résolvant les cryptarithmes, plus tard il contiendra un générateur aléatoire de cryptarithme
|
||||
|
||||
# Pour que le résolveur d'énigmes de cryptarithme fonctionne, il est nécessaire d'effectuer la commande :
|
||||
# pip install cpmpy
|
||||
|
||||
import numpy as np
|
||||
import re
|
||||
import itertools
|
||||
from cpmpy import *
|
||||
|
||||
# brief résout un cryptarithme donné et affiche le résultat
|
||||
# param ListeMots liste des mots du cryptarithme entré
|
||||
# param ListeOperateurs liste des opérateurs du cryptarithme entré
|
||||
# param ListeLettres liste des lettres associés à des variables du cryptarithme
|
||||
# param ListePosition liste temporaire servant à prendre les positions des variables dans la liste ListeLettres pour un mot que l'on remet ensuite a null
|
||||
# param ListePostion liste de liste de positions des variables dans la liste ListeLettres
|
||||
# param exposant10 liste temporaire servant à prendre les exposants pour chacune des lettres d'un mot
|
||||
# param exposants10 liste de liste d'exposant pour chque mot
|
||||
# param ConstraintAssemblingList liste des operations entre les variables d'un mot
|
||||
# param equalposition postion du egal dans la liste des opérateurs
|
||||
# param BigFirstEquationConstraintPart partie de contrainte avant le egal
|
||||
# param BigSecondEquationConstraintPart partie de contrainte après le egal
|
||||
# param model, model auquel on ajoute les contraintes
|
||||
|
||||
def cryptarithmeGenerique (s):
|
||||
|
||||
ListeMots=[]
|
||||
ListeOperateurs=[]
|
||||
ListeLettres=[]
|
||||
ListePosition=[]
|
||||
ListePositions=[]
|
||||
exposant10=[]
|
||||
exposants10=[]
|
||||
ConstraintAssemblingList=[]
|
||||
BigFirstEquationConstraintPart=[]
|
||||
equalposition=0
|
||||
# attrape la liste de lettres
|
||||
|
||||
lettres = "".join(set(re.findall("[A-Z]", s)))
|
||||
|
||||
# attrape la liste de mots
|
||||
|
||||
mots = s.split()
|
||||
if(mots[0]=='-'):
|
||||
print("pas de - comme opérateur devant la chaîne de caractère")
|
||||
return
|
||||
for i in range(0,len(mots),2):
|
||||
ListeMots.append(mots[i])
|
||||
# print(ListeMots)
|
||||
|
||||
# attrape la liste d'opérateurs
|
||||
for i in range(1,len(mots),2):
|
||||
ListeOperateurs.append(mots[i])
|
||||
# print(ListeOperateurs)
|
||||
|
||||
# associe à une lettre ses possibilités
|
||||
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)])
|
||||
#print(ListeLettres)
|
||||
|
||||
# associe pour chaque mot une liste des positions des variables contenu dans ListeLettres
|
||||
|
||||
for i in ListeMots:
|
||||
# print(i)
|
||||
for y in i:
|
||||
# print(y)
|
||||
for w in range(0,len(ListeLettres)):
|
||||
# print(w)
|
||||
# print(ListeLettres[w][0])
|
||||
if(y==ListeLettres[w][0]):
|
||||
ListePosition.append(w)
|
||||
break
|
||||
ListePositions.append(ListePosition)
|
||||
ListePosition=[]
|
||||
# print(ListePositions)
|
||||
|
||||
# associe pour chaque mot une liste d'exposant
|
||||
|
||||
for y in ListeMots:
|
||||
for i in range(0,len(y)):
|
||||
exposant10.append(10**i)
|
||||
exposants10.append(exposant10)
|
||||
exposant10=[]
|
||||
# print(exposants10)
|
||||
|
||||
# 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-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 = BigFirstEquationConstraintPart + ConstraintAssemblingList[i+1]
|
||||
if(ListeOperateurs[i]=='-'):
|
||||
BigFirstEquationConstraintPart = BigFirstEquationConstraintPart - ConstraintAssemblingList[i+1]
|
||||
if(ListeOperateurs[i]=='*'):
|
||||
BigFirstEquationConstraintPart = BigFirstEquationConstraintPart * ConstraintAssemblingList[i+1]
|
||||
if(ListeOperateurs[i]=='/'):
|
||||
BigFirstEquationConstraintPart = BigFirstEquationConstraintPart / ConstraintAssemblingList[i+1]
|
||||
print(BigFirstEquationConstraintPart)
|
||||
if(ListeOperateurs[i]=='='):
|
||||
equalposition=i
|
||||
break
|
||||
# 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 = BigSecondEquationConstraintPart + ConstraintAssemblingList[i+1]
|
||||
if(ListeOperateurs[i]=='-'):
|
||||
BigSecondEquationConstraintPart = BigSecondEquationConstraintPart + -ConstraintAssemblingList[i+1]
|
||||
if(ListeOperateurs[i]=='*'):
|
||||
BigSecondEquationConstraintPart = BigSecondEquationConstraintPart * ConstraintAssemblingList[i+1]
|
||||
if(ListeOperateurs[i]=='/'):
|
||||
BigSecondEquationConstraintPart = BigSecondEquationConstraintPart / ConstraintAssemblingList[i+1]
|
||||
print(BigSecondEquationConstraintPart)
|
||||
# print(BigSecondEquationConstraintPart)
|
||||
|
||||
# Création du model et de ses contraintes
|
||||
|
||||
model = Model()
|
||||
|
||||
# Mise en place de la contrainte globale
|
||||
|
||||
model += (BigFirstEquationConstraintPart == BigSecondEquationConstraintPart)
|
||||
|
||||
# Mise en place de la contrainte où toutes les lettres sont différentes
|
||||
|
||||
model += AllDifferent(ListeLettres[i][1] for i in range(0,len(ListeLettres)))
|
||||
|
||||
# Mise en place de la contrainte disant que les premières lettres des mots sont différentes de 0
|
||||
|
||||
for i in range(0,len(ListeMots)):
|
||||
model += (ListeLettres[ListePositions[i][0]][1]) > 0
|
||||
|
||||
|
||||
if model.solve():
|
||||
print(s)
|
||||
for i in range(0,len(ListeMots)):
|
||||
print(ListeMots[i]," =",[x.value() for x in [ListeLettres[ListePositions[i][y]][1] for y in range(0,len(ListeMots[i]))]])
|
||||
else:
|
||||
print("No solution found")
|
||||
|
||||
cryptarithmeGenerique("SEND + MORE = MONEY")
|
||||
cryptarithmeGenerique("HUIT + HUIT = SEIZE")
|
||||
cryptarithmeGenerique("UN + UN + NEUF = ONZE")
|
||||
cryptarithmeGenerique("UN + TROIS - NEUF = ONZE")
|
||||
cryptarithmeGenerique("UN * UN = ONZE")
|
||||
cryptarithmeGenerique("UNN / UN = UN")
|
@ -1,28 +0,0 @@
|
||||
def cul_de_chouette(valeur):
|
||||
res=list()
|
||||
for i in range(1, 7):
|
||||
for j in range(i, 7):
|
||||
for k in range(j, 7):
|
||||
if (i+j+k) == valeur:
|
||||
res.append([i, j, k])
|
||||
return res
|
||||
|
||||
def cul_de_chouetteVerif(valeur):
|
||||
res=list()
|
||||
for i in range(1, 7):
|
||||
for j in range(i, 7):
|
||||
for k in range(j, 7):
|
||||
if (i+j+k) == valeur:
|
||||
res.append([i, j, k])
|
||||
return res
|
||||
|
||||
def test_cul_de_chouette(n):
|
||||
listTest=[]
|
||||
for i in range(0,n):
|
||||
listTest.append(r.randint(3,18))
|
||||
for i in listTest:
|
||||
if(cul_de_chouette(i)!=cul_de_chouetteVerif(i)):
|
||||
return False
|
||||
return True
|
||||
|
||||
print(test_est_cul_de_chouette)
|
@ -1,112 +0,0 @@
|
||||
import random as r
|
||||
|
||||
# Fonction avec des int (Pas la bonne fonction)
|
||||
def binaire2unitaire(x):
|
||||
lentre=[]
|
||||
unitaire=[]
|
||||
rep=0
|
||||
for i in str(x):
|
||||
lentre.append(i)
|
||||
pre=lentre[0]
|
||||
for i in lentre:
|
||||
if(pre==i):
|
||||
rep+=1
|
||||
else:
|
||||
if(pre=="1"):
|
||||
unitaire.append(0)
|
||||
else:
|
||||
unitaire.append(0)
|
||||
unitaire.append(0)
|
||||
unitaire.append(" ")
|
||||
for j in range(rep):
|
||||
unitaire.append(0)
|
||||
unitaire.append(" ")
|
||||
rep=1
|
||||
pre=i
|
||||
if(pre=="1"):
|
||||
unitaire.append(0)
|
||||
else:
|
||||
unitaire.append(0)
|
||||
unitaire.append(0)
|
||||
unitaire.append(" ")
|
||||
for j in range(rep):
|
||||
unitaire.append(0)
|
||||
r=""
|
||||
for i in unitaire:
|
||||
r=r+str(i)
|
||||
return r
|
||||
|
||||
# fonction avec des str (bonne fonction)
|
||||
def binaire2unitaireV2(x):
|
||||
rep=0
|
||||
pre=x[0]
|
||||
unitaire=""
|
||||
for i in x:
|
||||
if(pre==i):
|
||||
rep+=1
|
||||
else:
|
||||
if(pre=="1"):
|
||||
unitaire=unitaire+"0 "
|
||||
else:
|
||||
unitaire=unitaire+"00 "
|
||||
for j in range(rep):
|
||||
unitaire=unitaire+"0"
|
||||
unitaire=unitaire+" "
|
||||
rep=1
|
||||
pre=i
|
||||
if(pre=="1"):
|
||||
unitaire=unitaire+"0 "
|
||||
else:
|
||||
unitaire=unitaire+"00 "
|
||||
for i in range(rep):
|
||||
unitaire=unitaire+"0"
|
||||
return unitaire
|
||||
|
||||
|
||||
def binaire2unitaireVerif(x):
|
||||
rep=0
|
||||
pre=x[0]
|
||||
unitaire=""
|
||||
for i in x:
|
||||
if(pre==i):
|
||||
rep+=1
|
||||
else:
|
||||
if(pre=="1"):
|
||||
unitaire=unitaire+"0 "
|
||||
else:
|
||||
unitaire=unitaire+"00 "
|
||||
for j in range(rep):
|
||||
unitaire=unitaire+"0"
|
||||
unitaire=unitaire+" "
|
||||
rep=1
|
||||
pre=i
|
||||
if(pre=="1"):
|
||||
unitaire=unitaire+"0 "
|
||||
else:
|
||||
unitaire=unitaire+"00 "
|
||||
for i in range(rep):
|
||||
unitaire=unitaire+"0"
|
||||
return unitaire
|
||||
|
||||
|
||||
|
||||
def testChuckNorris(x):
|
||||
l="0000000"
|
||||
if(binaire2unitaireV2(l)!="00 0000000"):
|
||||
return False
|
||||
l="1111111"
|
||||
if(binaire2unitaireV2(l)!="0 0000000"):
|
||||
return False
|
||||
l="1101001"
|
||||
if(binaire2unitaireV2(l)!="0 00 00 0 0 0 00 00 0 0"):
|
||||
return False
|
||||
l=""
|
||||
for i in range(x):
|
||||
for j in range(r.randint(1,10)):
|
||||
l=l+str(r.randint(0,1))
|
||||
if(binaire2unitaireV2(l)!=binaire2unitaireVerif(l)):
|
||||
return False
|
||||
l=""
|
||||
return True
|
||||
|
||||
print(testChuckNorris(10))
|
@ -1,83 +0,0 @@
|
||||
import random as r
|
||||
|
||||
def Encrypt(text, key):
|
||||
result = ""
|
||||
for i in range(len(text)):
|
||||
char = text[i]
|
||||
if(char==" "):
|
||||
result+=" "
|
||||
elif (char.isupper()):
|
||||
result += chr((ord(char) + key-65) % 26 + 65)
|
||||
else:
|
||||
result += chr((ord(char) + key - 97) % 26 + 97)
|
||||
return result
|
||||
|
||||
def EncryptVerif(text, key):
|
||||
result = ""
|
||||
for i in range(len(text)):
|
||||
char = text[i]
|
||||
if(char==" "):
|
||||
result+=" "
|
||||
elif (char.isupper()):
|
||||
result += chr((ord(char) + key-65) % 26 + 65)
|
||||
else:
|
||||
result += chr((ord(char) + key - 97) % 26 + 97)
|
||||
return result
|
||||
|
||||
|
||||
def Decrypt(text, key):
|
||||
result = ""
|
||||
for i in range(len(text)):
|
||||
char = text[i]
|
||||
if(char==" "):
|
||||
result+=" "
|
||||
elif (char.isupper()):
|
||||
result += chr((ord(char) - key-65) % 26 + 65)
|
||||
else:
|
||||
result += chr((ord(char) - key - 97) % 26 + 97)
|
||||
return result
|
||||
|
||||
def DecryptVerif(text, key):
|
||||
result = ""
|
||||
for i in range(len(text)):
|
||||
char = text[i]
|
||||
if(char==" "):
|
||||
result+=" "
|
||||
elif (char.isupper()):
|
||||
result += chr((ord(char) - key-65) % 26 + 65)
|
||||
else:
|
||||
result += chr((ord(char) - key - 97) % 26 + 97)
|
||||
return result
|
||||
|
||||
def testEncrypte(x):
|
||||
if(Encrypt("Hello world",2)!="Jgnnq yqtnf"):
|
||||
return False
|
||||
if(Encrypt("Scripted",9)!="Blarycnm"):
|
||||
return False
|
||||
for i in range(x):
|
||||
l=""
|
||||
cle=r.randint(1,26)
|
||||
for i in range(r.randint(1,10)):
|
||||
l+=chr(r.randint(97,122))
|
||||
if(Encrypt(l,cle)!=EncryptVerif(l,cle)):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def testDecrypte(x):
|
||||
if(Decrypt("Hello world",2)!="Jgnnq yqtnf"):
|
||||
return False
|
||||
if(Decrypt("Scripted",9)!="Blarycnm"):
|
||||
return False
|
||||
for i in range(x):
|
||||
l=""
|
||||
cle=r.randint(1,26)
|
||||
for i in range(r.randint(1,10)):
|
||||
l+=chr(r.randint(97,122))
|
||||
if(Decrypt(l,cle)!=DecryptVerif(l,cle)):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
|
||||
print(Decrypt("Scripted",4))
|
@ -1,32 +0,0 @@
|
||||
import random as r
|
||||
def hanoi(nb_disks,start, middle, end):
|
||||
l=[]
|
||||
hanoi_rec(l,nb_disks,start, middle, end)
|
||||
return l
|
||||
|
||||
def hanoiVerif(nb_disks,start, middle, end):
|
||||
l=[]
|
||||
hanoi_rec(l,nb_disks,start, middle, end)
|
||||
return l
|
||||
|
||||
|
||||
def hanoi_rec(l,nb_disks, start, middle, end):
|
||||
if(nb_disks == 1):
|
||||
return l.append([start,end])
|
||||
else:
|
||||
hanoi_rec(l,nb_disks - 1, start, end, middle)
|
||||
l.append([start,end])
|
||||
hanoi_rec(l,nb_disks - 1, middle, start, end)
|
||||
|
||||
def testhanoi(x):
|
||||
if(hanoi(3,"A","B","C")!=[['A','C'],['A','B'],['C','B'],['A','C'],['B','A'],['B','C'],['A','C']]):
|
||||
return False
|
||||
for i in range(x):
|
||||
j=r.randint(1,4)
|
||||
if(hanoi(j,"Z","E","R")!=hanoiVerif(j,"Z","E","R")):
|
||||
return False
|
||||
return True
|
||||
|
||||
print(testhanoi(5))
|
||||
|
||||
|
@ -1,32 +0,0 @@
|
||||
import random as r
|
||||
|
||||
def estPalindrome(var):
|
||||
if(var == var[::-1]):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def estPalindromeVerif(var):
|
||||
if(var == var[::-1]):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def testPalindrome(x):
|
||||
l=[1,2,3,2,1]
|
||||
if(estPalindrome(l)==False):
|
||||
return False
|
||||
l=[9,5,7,7,9]
|
||||
if(estPalindrome(l)==True):
|
||||
return False
|
||||
l=[]
|
||||
for i in range(x):
|
||||
for j in range(r.randint(1,10)):
|
||||
l.append(r.randint(0,9))
|
||||
if(estPalindromeVerif(l)!=estPalindrome(l)):
|
||||
return False
|
||||
l=[]
|
||||
return True
|
||||
|
||||
|
@ -1,14 +0,0 @@
|
||||
# Affiche Hello world !
|
||||
|
||||
print("Hello World !")
|
||||
|
||||
# Declaration de variable
|
||||
|
||||
num = 1
|
||||
string = "Oi"
|
||||
liste=[num,string]
|
||||
|
||||
print(liste)
|
||||
|
||||
|
||||
# Utilisation de fonction
|
@ -1,42 +0,0 @@
|
||||
import random as r
|
||||
|
||||
def triangleDePascal(n):
|
||||
if(n==0):
|
||||
return []
|
||||
if(n==1):
|
||||
return [[1]]
|
||||
triangle=[[1],[1, 1]]
|
||||
columns=n
|
||||
for line in range(2,n):
|
||||
triangle.append([1])
|
||||
for column in range(1, line):
|
||||
triangle[line].append(triangle[line - 1][column - 1] + triangle[line - 1][column])
|
||||
triangle[line].append(1)
|
||||
return triangle
|
||||
|
||||
#t=triangle(8)
|
||||
#for line in range(0,7):
|
||||
# print(t[line])
|
||||
|
||||
def estTriangleDePascal(n):
|
||||
if(n==0):
|
||||
return []
|
||||
if(n==1):
|
||||
return [[1]]
|
||||
triangle=[[1],[1, 1]]
|
||||
columns=n
|
||||
for line in range(2,n):
|
||||
triangle.append([1])
|
||||
for column in range(1, line):
|
||||
triangle[line].append(triangle[line - 1][column - 1] + triangle[line - 1][column])
|
||||
triangle[line].append(1)
|
||||
return triangle
|
||||
|
||||
def testTriangleDePascal(n):
|
||||
listTest=[0,1]
|
||||
for i in range(0,n):
|
||||
listTest.append(r.randint(5,140))
|
||||
for i in listTest:
|
||||
if(triangleDePascal(i)!=estTriangleDePascal(i)):
|
||||
return False
|
||||
return True
|
Before Width: | Height: | Size: 1.7 MiB After Width: | Height: | Size: 1.7 MiB |
Before Width: | Height: | Size: 1.6 MiB After Width: | Height: | Size: 1.6 MiB |
Before Width: | Height: | Size: 211 KiB After Width: | Height: | Size: 211 KiB |
Before Width: | Height: | Size: 3.2 MiB After Width: | Height: | Size: 3.2 MiB |
Before Width: | Height: | Size: 2.1 MiB After Width: | Height: | Size: 2.1 MiB |
Before Width: | Height: | Size: 3.8 MiB After Width: | Height: | Size: 3.8 MiB |
Before Width: | Height: | Size: 2.5 MiB After Width: | Height: | Size: 2.5 MiB |
Before Width: | Height: | Size: 2.9 MiB After Width: | Height: | Size: 2.9 MiB |
Before Width: | Height: | Size: 1.6 MiB After Width: | Height: | Size: 1.6 MiB |
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.2 MiB |
Before Width: | Height: | Size: 823 KiB After Width: | Height: | Size: 823 KiB |
Before Width: | Height: | Size: 1.6 MiB After Width: | Height: | Size: 1.6 MiB |
Before Width: | Height: | Size: 6.5 MiB After Width: | Height: | Size: 6.5 MiB |
Before Width: | Height: | Size: 1.6 MiB After Width: | Height: | Size: 1.6 MiB |
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 771 B After Width: | Height: | Size: 771 B |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |