diff --git a/Exo4Tri.py b/Exo4Tri.py new file mode 100644 index 0000000..3d68094 --- /dev/null +++ b/Exo4Tri.py @@ -0,0 +1,25 @@ +def tri_par_selection(tableau): + n = len(tableau) + for i in range(n): + min_index = i + for j in range(i + 1, n): + if tableau[j] < tableau[min_index]: + min_index = j + tableau[i], tableau[min_index] = tableau[min_index], tableau[i] + return tableau + +def triJL(tableau): + for i in range(len(tableau)): + tableau[i] = tri_par_selection(tableau[i]) + + for i in range(len(tableau)): + for j in range(i + 1, len(tableau)): + if sum(tableau[j]) < sum(tableau[i]): + tableau[i], tableau[j] = tableau[j], tableau[i] + + return tableau + +tableau = [[0, 3, 2], [9, 4, 5], [4, 1, 3]] +print("tableau avant triage : ", tableau) +resultat = triJL(tableau) +print("Tableau triƩ :", resultat)