Skip to content
Snippets Groups Projects
Commit 9289a0f8 authored by Romain Vuillemot's avatar Romain Vuillemot
Browse files

udpates

parent 1ffb4e62
No related branches found
No related tags found
No related merge requests found
#####################################
## 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
# 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
# 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
def addition(a, b):
return a + b
\ No newline at end of file
File moved
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
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
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 ?")
# 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
File moved
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
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
# Résolution équation quadratique
from math import sqrt; from math import sqrt;
# résolution équation quadratique
def trinome(a, b, c): def trinome(a, b, c):
delta = b**2 - 4*a*c delta = b**2 - 4*a*c
if delta > 0.0: if delta > 0.0:
......
File moved
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
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment