Recently, I was playing one of my favorites games, and I came accross a problem: This game have a store, and in that store, skins to especific characters are selled, and I'm planning to buy them. There is 34 skins avaliable, and each one costs 1800 credits (the game currency). The only way of earning those credits is buying packs of it with real money.
There is 6 packs, as I show below:
Pack | Amount of credits | Price |
---|---|---|
1 | 600 | 19.90 |
2 | 1200 | 41.50 |
3 | 2670 | 83.50 |
4 | 4920 | 144.90 |
5 | 7560 | 207.90 |
6 | 16000 | 414.90 |
My first tought was to calculate what was the best way (aka the way of spending less money) to buy any quantity of skins (1 -> 34), but buying N amount of just a single type of pack. So, I wrote this code:
import numpy as np
import pandas as pd
#Cost per Skin (Cs)
c_ps = 1800
#Amount of credits per pack (Qp)
q_ppc = [600, 1200, 2670, 4920, 7560, 16000]
#Cost per pack (Cp)
c_ppc = [19.9, 41.5, 83.3, 144.9, 207.9, 414.9]
#Amount of skins to be buyed (Qd)
qtd_d = 0
#Total cost of the transaction (Ct)
ct_total = 0
#Total amount of packs (Pt)
qtd_total = 0
#Complete list
lista_completa = np.zeros((34,4), dtype=np.float16)
#count var
j = 0
while True:
#best option (Bb)
best_opt = 0
#best amount (Bq)
best_qtd = 0
#best cost (Bc)
best_cost = 50000
qtd_d += 1
#Cost of the nº of skins to be buyed
custo = (c_ps * qtd_d)
for opt in q_ppc:
i = q_ppc.index(opt)
qtd_total = m.ceil(custo/opt)
ct_total = (qtd_total * c_ppc[i])
if best_cost > ct_total:
best_opt = opt
best_qtd = qtd_total
best_cost = ct_total
lista_completa[j] = [int(qtd_d), int(best_opt), int(best_qtd), float(np.round(best_cost, decimals = 1))]
j += 1
if j == 34:
break
float_formatter = '{:.2F}'.format
np.set_printoptions(formatter={'float_kind':float_formatter})
pd.set_option('display.float_format','{:.2f}'.format)
df = pd.DataFrame(lista_completa, columns = ['Quantidade desejada',
'Melhor opção de pacote',
'Quantidade de pacotes necessária',
'Custo total'])
df.set_index('Quantidade desejada', inplace = True)
df
That gave me the following output:
Amount of Skins | Best pack option | Required amount of packs | Final Cost |
---|---|---|---|
1.00 | 600.00 | 3.00 | 59.69 |
2.00 | 600.00 | 6.00 | 119.38 |
3.00 | 600.00 | 9.00 | 179.12 |
4.00 | 7560.00 | 1.00 | 207.88 |
5.00 | 4920.00 | 2.00 | 289.75 |
6.00 | 600.00 | 18.00 | 358.25 |
7.00 | 16000.00 | 1.00 | 415.00 |
8.00 | 16000.00 | 1.00 | 415.00 |
9.00 | 600.00 | 27.00 | 537.50 |
10.00 | 4920.00 | 4.00 | 579.50 |
11.00 | 7560.00 | 3.00 | 623.50 |
12.00 | 7560.00 | 3.00 | 623.50 |
13.00 | 4920.00 | 5.00 | 724.50 |
14.00 | 16000.00 | 2.00 | 830.00 |
15.00 | 16000.00 | 2.00 | 830.00 |
16.00 | 16000.00 | 2.00 | 830.00 |
17.00 | 16000.00 | 2.00 | 830.00 |
18.00 | 4920.00 | 7.00 | 1014.50 |
19.00 | 4920.00 | 7.00 | 1014.50 |
20.00 | 7560.00 | 5.00 | 1040.00 |
21.00 | 7560.00 | 5.00 | 1040.00 |
22.00 | 16000.00 | 3.00 | 1245.00 |
23.00 | 16000.00 | 3.00 | 1245.00 |
24.00 | 16000.00 | 3.00 | 1245.00 |
25.00 | 16000.00 | 3.00 | 1245.00 |
26.00 | 16000.00 | 3.00 | 1245.00 |
27.00 | 4920.00 | 10.00 | 1449.00 |
28.00 | 7560.00 | 7.00 | 1455.00 |
29.00 | 7560.00 | 7.00 | 1455.00 |
30.00 | 4920.00 | 11.00 | 1594.00 |
31.00 | 16000.00 | 4.00 | 1660.00 |
32.00 | 16000.00 | 4.00 | 1660.00 |
33.00 | 16000.00 | 4.00 | 1660.00 |
34.00 | 16000.00 | 4.00 | 1660.00 |
Now, my question is: Is there a way to calculate and get the best combination of packs mixed or not, for each number of skins?
I didn't think of anything but to first calculate the maximum amount of packs which I would need to buy all the 34 skins (102 packs of 600 credits). But I got stuck on this tought, and hope for you to help me solve this!
Thank you all, in advance!