I’m having a hard time finding a solution for this and I don’t even know if it’s possible…
I’m developing a small app where I have 5 types of items with different stats, 7 levels (some have only 3 levels), and I would like to find all the items stats combinaisons.
Ex:
- Item 1 lvl 1, Item 1 lvl 1 + Item 1 lvl 1 + Item 1 lvl 1 + Item 1 lvl 1
- Item 1 lvl 2, Item 1 lvl 1 + Item 1 lvl 1 + Item 1 lvl 1 + Item 1 lvl 1
- Item 1 lvl 3, Item 1 lvl 1 + Item 1 lvl 1 + Item 1 lvl 1 + Item 1 lvl 1
- Item 1 lvl 4, Item 1 lvl 1 + Item 1 lvl 1 + Item 1 lvl 1 + Item 1 lvl 1
- ….
- Item 7 lvl 7, Item 1 lvl 1 + Item 1 lvl 1 + Item 1 lvl 1 + Item 1 lvl 1
- Item 7 lvl 7, Item 1 lvl 2 + Item 1 lvl 1 + Item 1 lvl 1 + Item 1 lvl 1
- Item 7 lvl 7, Item 1 lvl 3 + Item 1 lvl 1 + Item 1 lvl 1 + Item 1 lvl 1
- …
So it will generate around 1 934 917 632 possibilities.
What should be the best approach to do this?
Is it ok to store those values into a Mysql Database?
Is there any way to optimize this? Do the calculation live with a lot of filters to reduce the possible combinaisons?
I already try How to get all combinations from multiple arrays? it works fine, but I only test with 40 possibilities, I’am more concerned about the Database part…
EDIT:
Each combinaison will give an amount of token, the tool would be used to find the combinaison that give more token than a previous combinaison. –
Thank you guys!
2
Answers
You can use the following code to generate all the combinations:
All combinations can be mapped from the numbers from 0 to 1 934 917 631. It just takes some DIVs and MODs to split an integer into 5 numbers, each between 0 and 71. That might be a better starting point.
And if you want to store those 2 billion rows on disk, consider storing just 2 billion numbers, then pick them apart to find the 5 thingies.
In MySQL, a row with 5
TINYINT UNSIGNED
columns is another approach. It’s not quite as compact as a singleINT UNSIGNED
, but it might (or might not) be easier to work with.