diff --git a/TD01/code/01-git.py b/TD01/code/01-git.py deleted file mode 100644 index 918d1b34da3f0ad82511ea5e52a089385e438e7a..0000000000000000000000000000000000000000 --- a/TD01/code/01-git.py +++ /dev/null @@ -1,13 +0,0 @@ -##################################### -## GitLab de l'Ecole Centrale de Lyon -# -# https://gitlab.ec-lyon.fr/ -# -##################################### - -## Comment vous connecter ? -# Avec vos identifiants ECL. - -## A quoi ça sert ? -# Nous utiliserons GitLab pendant les cours d'informatique afin de vous -# distribuer le code et vous permettre de le sauvegarder. GitLab est très utilisé en entreprise, il vous est donc important de l'utiliser très rapidement car cela vous sera utile pour vos stages, projects, etc. \ No newline at end of file diff --git a/TD01/code/01-git_exercices.py b/TD01/code/01-git_exercices.py deleted file mode 100644 index a77707ae7fde08e7212f41785a7f650a91bee4c5..0000000000000000000000000000000000000000 --- a/TD01/code/01-git_exercices.py +++ /dev/null @@ -1,8 +0,0 @@ -# Faire un premier commit avec une fonction déjà existante - -def addition(a, b): - return a + b - -# Tester que cela fonctionne - -# Afficher le résultat sur le site gitlab diff --git a/TD01/code/02-python.py b/TD01/code/02-python.py deleted file mode 100644 index ad9b69f3ef20161761b264536d1139d76326d8c5..0000000000000000000000000000000000000000 --- a/TD01/code/02-python.py +++ /dev/null @@ -1,9 +0,0 @@ -# Faire un premier test d'une fonction Python - -## Vérifiez votre numéro de version -# Afficher le numéro de version avec la commande suivante -# dans un terminal - -# python ––version - -# > La version doit être égale ou supérieure à 3.7 \ No newline at end of file diff --git a/TD01/code/addition.py b/TD01/code/addition.py new file mode 100644 index 0000000000000000000000000000000000000000..b2fcfda079ea637f4cbbb5b5bcfde6ae22ec657c --- /dev/null +++ b/TD01/code/addition.py @@ -0,0 +1,2 @@ +def addition(a, b): + return a + b \ No newline at end of file diff --git a/TD01/code/03-commentaires.py b/TD01/code/commentaires.py similarity index 100% rename from TD01/code/03-commentaires.py rename to TD01/code/commentaires.py diff --git a/TD01/code/fibo-comp.py b/TD01/code/fibo-comp.py new file mode 100644 index 0000000000000000000000000000000000000000..b92d2d78044d71238ab0095a6ad7f42d0cf4744d --- /dev/null +++ b/TD01/code/fibo-comp.py @@ -0,0 +1,14 @@ +def fibo1(f2, f1, i): + if i > 0: + return fibo1(f1, f2+f1, i-1) + else: + return f2 + + +def fibo2(f2, f1, i): + while i > 0: + f2, f1, i = f1, f2+f1, i-1 + return f2 + +print(fibo1(6)) +print(fibo2(6)) \ No newline at end of file diff --git a/TD01/code/fibo-mem.py b/TD01/code/fibo-mem.py new file mode 100644 index 0000000000000000000000000000000000000000..bfcd71c4e9f7263d1fe04b49914b3b5ee39c709d --- /dev/null +++ b/TD01/code/fibo-mem.py @@ -0,0 +1,23 @@ +def fib(n, lookup): + + # Cas d'arrêt + if n == 0 or n == 1 : + lookup[n] = n + + # On calcule la valeur si pas déjà calculée + if lookup[n] is None: + lookup[n] = fib(n-1 , lookup) + fib(n-2 , lookup) + + # On renvoie la n-eme valeur + return lookup[n] + +def main(): + n = 6 + max = 100 + # Initialise la table de cache + lookup = [None]*(max) + print("Le nombre de fibonacci est ", fib(n, lookup)) + # Le nombre de fibonacci est 8 + +if __name__=="__main__": + main() \ No newline at end of file diff --git a/TD01/code/graphe_dico.py b/TD01/code/graphe_dico.py new file mode 100644 index 0000000000000000000000000000000000000000..e8fd6a919321d3eb27cbc34b033fddce1b847810 --- /dev/null +++ b/TD01/code/graphe_dico.py @@ -0,0 +1,25 @@ +G = { + 'A' : ['B','C', 'F'], + 'B' : ['D', 'E'], + 'C' : ['F'], + 'D' : ['G'], + 'E' : ['F'], + 'F' : ['G', 'H'], + 'G' : ['H'], + 'H' : [] +} + +v = set() + +def traitement(v, G, n): + if n not in v: + v.add(n) + print(n) + for m in G[n]: + traitement(v, G, m) + +if __name__ == '__main__': + traitement(v, G, 'A') + + if len(v) > 0: + print("Que se passe-t-il ?") diff --git a/TD01/code/graphe_sim.py b/TD01/code/graphe_sim.py new file mode 100644 index 0000000000000000000000000000000000000000..43ee0648d1385eb03331001bb005e9e3ad7b3fb4 --- /dev/null +++ b/TD01/code/graphe_sim.py @@ -0,0 +1,37 @@ +# Par exemple pour Fool et Sage vous devez renvoyez le résultat suivant : +# +# FOOL +# POOL +# POLL +# POLE +# PALE +# SALE +# SAGE +# +# SOLUTION: + +graph = {'A': ['B', 'C'], + 'B': ['C', 'D'], + 'C': ['D'], + 'D': ['C'], + 'E': ['F'], + 'F': ['C'] +} + +def chemin(graphe, source, destination, visite=None): + + if source == destination: + return [destination] + else: + visite = visite or set() + for s in graphe[source]: + if s not in visite: + visite.add(s) + print("trace:", source + " > " + s) + sous_chemin = chemin(graphe, s, destination, visite) + if sous_chemin is not None: + return [source] + sous_chemin + +print(chemin(simGraphe(["AA", "AB", "BC", "AC", "DD"]), "AA", "BC")) + +# ['AA', 'AB', 'AC', 'BC'] \ No newline at end of file diff --git a/TD01/code/04-bases_exercices.py b/TD01/code/lire_entier.py similarity index 100% rename from TD01/code/04-bases_exercices.py rename to TD01/code/lire_entier.py diff --git a/TD01/code/liste_liee.py b/TD01/code/liste_liee.py new file mode 100644 index 0000000000000000000000000000000000000000..bd6276ac795d12b2236220d56718a139c4f9e7c0 --- /dev/null +++ b/TD01/code/liste_liee.py @@ -0,0 +1,33 @@ +class Node: + def __init__(self, data = None, next = None): + self.data = data + self.next = next + +class LinkedList: + def __init__(self): + self.head = None + + def listprint(self): + printval = self.head + while printval is not None: + print(printval.dataval) + printval = printval.nextval + + def push(self, n): + if self.head is None: + self.head = Node(n) + else: + node = self.head + while node.next is not None: + node = node.next + node.next = Node(n) + + def detectLoop(self): + s = set() + temp = self.head + while (temp): + if (temp in s): + return True + s.add(temp) + temp = temp.next + return False \ No newline at end of file diff --git a/TD01/code/listes_lieee_test_boucle.py b/TD01/code/listes_lieee_test_boucle.py new file mode 100644 index 0000000000000000000000000000000000000000..a658bbd76f878429a0fc34968643f5f2a9597cf2 --- /dev/null +++ b/TD01/code/listes_lieee_test_boucle.py @@ -0,0 +1,15 @@ +from liste_liee import * + +ll = liste_liee() # Ajout de données +ll.push(20) +ll.push(4) +ll.push(15) +ll.push(10) + +# Création d'une boucle +ll.head.next.next.next.next = ll.head; + +if( ll.detectLoop()): + print ("Il y a une boucle !") +else : + print ("Pas de boucle ! ") \ No newline at end of file diff --git a/TD01/code/racines.py b/TD01/code/racines.py index b5c6a1b7844b47795b048ec5b47f469500be02c5..fb23af6c0d9ee9a8b621cc84afa76c24d55d3089 100644 --- a/TD01/code/racines.py +++ b/TD01/code/racines.py @@ -1,5 +1,7 @@ +# Résolution équation quadratique + from math import sqrt; -# résolution équation quadratique + def trinome(a, b, c): delta = b**2 - 4*a*c if delta > 0.0: diff --git a/TD01/code/02-python_exercices.py b/TD01/code/test_version_python.py similarity index 100% rename from TD01/code/02-python_exercices.py rename to TD01/code/test_version_python.py diff --git a/TD01/code/tri_fusion.py b/TD01/code/tri_fusion.py new file mode 100644 index 0000000000000000000000000000000000000000..e4bdb86721ad39651ee67f4c0aadafaa1c55e788 --- /dev/null +++ b/TD01/code/tri_fusion.py @@ -0,0 +1,31 @@ +def mergeSort(arr): + if len(arr) >1: + mid = len(arr)//2 #Finding the mid of the array + L = arr[:mid] # Dividing the array elements + R = arr[mid:] # into 2 halves + + mergeSort(L) # Sorting the first half + mergeSort(R) # Sorting the second half + + i = j = k = 0 + + # Copy data to temp arrays L[] and R[] + while i < len(L) and j < len(R): + if L[i] < R[j]: + arr[k] = L[i] + i+=1 + else: + arr[k] = R[j] + j+=1 + k+=1 + + # Checking if any element was left + while i < len(L): + arr[k] = L[i] + i+=1 + k+=1 + + while j < len(R): + arr[k] = R[j] + j+=1 + k+=1 \ No newline at end of file diff --git a/TD01/code/tri_rapide.py b/TD01/code/tri_rapide.py new file mode 100644 index 0000000000000000000000000000000000000000..48ed21ca20232b6c8366ee3fef704543db26b863 --- /dev/null +++ b/TD01/code/tri_rapide.py @@ -0,0 +1,15 @@ +def quicksort(t): + if t == []: + return [] + else: + pivot = t[0] + t1 = [] + t2 = [] + for x in t[1:]: + if x<pivot: + t1.append(x) + else: + t2.append(x) + return quicksort(t1) + [pivot] + quicksort(t2) + +quicksort([1,4, 5]) \ No newline at end of file