I have an array in the format:
$array = array(
0 => array(
'name' => 'Item 1',
'level' => 1,
'points' => 10
),
1 => array(
'name' => 'Item 1',
'level' => 2,
'points' => 12
),
...
24 => array(
'name' => 'Item 1',
'level' => 25,
'points' => 100
),
25 => array(
'name' => 'Item 2',
'level' => 1,
'points' => 10
),
26 => array(
'name' => 'Item 2',
'level' => 2,
'points' => 12
),
...
34 => array(
'name' => 'Item 2',
'level' => 10,
'points' => 30
),
...
97 => array(
'name' => 'Item 10',
'level' => 1,
'points' => 14
),
...
108 => array(
'name' => 'Item 10',
'level' => 12,
'points' => 200
),
...
324 => array(...)
);
From the above, please infer:
- Each "Item" has varying levels, for example, "Item 1" has 24 levels, but some Items can have up to 30 levels.
- Points are not incremental or derived by a (known) formula.
- There are 324 total "Items" lines in the reference data (18 Items with varying levels).
The user will input a point number of, say 8000, and this data array need to somehow give me a list of combinations of at most one of each "Item", but not necessarily one of each "Item" where the sum of points for these "Items" add up to exactly 8000 points.
The only way I can think of is to make a sort-of rainbow table with point values in it for each possible combinations, as an attempt at recursion made my machine ran out of memory.
For your reference, the number of levels for the 18 "Items" (in no particular order) are:
30, 25, 20, 15, 1, 1, 3, 1, 3, 20, 25, 30, 30, 30, 30, 30, 20, 10 = 324
Levels.
I am not sure of the math, but I think there will be 30 * 25 * 20 ... * 20 * 10
rows in the table, so not sure that is feasible or possible.
How would I tackle this problem to get a result (if any) that matches user's input points?