May-12-2018, 08:13 PM
Hello I have a question i'm doing a program that do this:
Imagine you are a Pokemon trainer and you want to fill your bag with
three types of items; pokeballs, potions and rare candies. Each pokeball cost $200 and gives you 1000 experience points (exp). Potions cost $300 and gives you 1800 exp and finally rare candies cost \verb|$1000| and gives you 7000 exp. You have $25,000 (pokedollars) and obviously, you want to get the maximum possible experience spending as much of your money:
So I made the following program:
it gives me : combinations= (1,0,0,200,1000,1,1,0,500,2800,1,1,1,1500,9800 ... )
but it should be: Combinations= [(1,0,0,200,1000),(1,1,0,500,2800),(1,1,1,1500,9800) ...]
and I don't know how to cut my vector in a vector made by vectors of 4 coordinates each one for short vectors I know that:
if a=[1,2,3,4,5,6,7,8,9]
and I do: b=[(a[0:3]),(a[3:6]),(a[6:10])]
it brings me b=[[1,2,3],[4,5,6],[7,8,9]]
But I don't know how to use that in my program or if there is another way to do it, Thanks!
Imagine you are a Pokemon trainer and you want to fill your bag with
three types of items; pokeballs, potions and rare candies. Each pokeball cost $200 and gives you 1000 experience points (exp). Potions cost $300 and gives you 1800 exp and finally rare candies cost \verb|$1000| and gives you 7000 exp. You have $25,000 (pokedollars) and obviously, you want to get the maximum possible experience spending as much of your money:
So I made the following program:
#amount of money pokeball = 200 potion = 300 candy = 1000 #amount of exp pokeball2 = 1000 potion2 = 1800 candy2 = 7000 #total money money = 25000 total= 0 exp = 0 #list used combinations = [] combination= [] lpokeball=[] lpotion=[] lcandy=[] ltotal=[] n = money / pokeball for i in range (0,n+1): lpokeball.append(i*pokeball) print('All the combinations of pokeballs are:') print (lpokeball) m= money / potion for i in range (0,m+1): lpotion.append(i*potion) print('All the combinations of potions are:') print(lpotion) b = money / candy for i in range (0,b+1): lcandy.append(i*candy) print('All the combinations of candys are:') for i in lpokeball: for j in lpotion: for k in lcandy: total = (i+j+k) if total <= money and total >= 20000: #at the beggining #I only has if #total <= money #but that gives me #a lot of #vectors, so I #added the other #conditon to give #me just the #betters #combination combination.append(i/pokeball) combination.append(j/potion) combination.append(k/candy) combination.append(total) exp = (i/pokeball)*pokeball2 + (j/potion)*potion2 + (k/candy)*candy2 combination.append(exp) #combinations.append(combination) I think with this it was going to be separated by vectors but no #combination.sort() print(combination) #print(combinations)And my program works but,
it gives me : combinations= (1,0,0,200,1000,1,1,0,500,2800,1,1,1,1500,9800 ... )
but it should be: Combinations= [(1,0,0,200,1000),(1,1,0,500,2800),(1,1,1,1500,9800) ...]
and I don't know how to cut my vector in a vector made by vectors of 4 coordinates each one for short vectors I know that:
if a=[1,2,3,4,5,6,7,8,9]
and I do: b=[(a[0:3]),(a[3:6]),(a[6:10])]
it brings me b=[[1,2,3],[4,5,6],[7,8,9]]
But I don't know how to use that in my program or if there is another way to do it, Thanks!