Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Algorithme aléatoire
- from random import*
- #initiation des variables
- tab_valeur=[1, 2, 9, 7, 6, 5, 6, 4]
- tab_poids=[5, 6, 7, 1, 8, 2, 3, 4]
- tab_id=[p for p in range (len(tab_valeur))]
- poids_max=10
- tab_sol=[]
- poids_sol=0
- valeur_sol=0
- #demarage du programme
- while(len(tab_valeur)!=0)and(poids_sol < poids_max):
- print(indice)
- #je teste un objet
- if poids_sol+tab_poids[indice]<poids_max:
- tab_sol.append(tab_id[indice])
- poids_sol=poids_sol+tab_poids[indice]
- valeur_sol=valeur_sol+tab_valeur[indice]
- #l'objet tester est retiré
- tab_valeur.pop(indice)
- tab_poids.pop(indice)
- tab_id.pop(indice)
- print("valeur",valeur_sol)
- print("masse",poids_sol)
- print("numero",tab_sol)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement