Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #Algorithme aléatoire
  2.  
  3. from random import*
  4. #initiation des variables
  5.  
  6. tab_valeur=[1, 2, 9, 7, 6, 5, 6, 4]
  7. tab_poids=[5, 6, 7, 1, 8, 2, 3, 4]
  8. tab_id=[p for p in range (len(tab_valeur))]
  9.  
  10. poids_max=10
  11.  
  12. tab_sol=[]
  13. poids_sol=0
  14. valeur_sol=0
  15.  
  16. #demarage du programme
  17.  
  18. while(len(tab_valeur)!=0)and(poids_sol < poids_max):
  19. print(indice)
  20.  
  21. #je teste un objet
  22. if poids_sol+tab_poids[indice]<poids_max:
  23. tab_sol.append(tab_id[indice])
  24. poids_sol=poids_sol+tab_poids[indice]
  25. valeur_sol=valeur_sol+tab_valeur[indice]
  26. #l'objet tester est retiré
  27. tab_valeur.pop(indice)
  28. tab_poids.pop(indice)
  29. tab_id.pop(indice)
  30.  
  31. print("valeur",valeur_sol)
  32. print("masse",poids_sol)
  33. print("numero",tab_sol)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement