I am writing an app in javascript to try to figure out item builds for characters in a video game. There are about 25 top-tier items, and you can carry 6 at a time. They have very different effects, which leads me to believe that while one item may seem like it isn't very good by itself, it can become much stronger when combined with others. I can elaborate on that if there is interest.
Questions:
How can I get a list of all the different distinct combinations of 6 items? How many combinations will there be? Is it just 25c6 (~134k)? Or do I need to remove duplicates? (Sorry, I've been out of math class awhile.)
How would you implement something like this in Javascript? Is there already a math library that can do this? (Specifically, iterate through all of the possible combinations of items.)
Does it seem possible to brute force calculate the damage of all the possible combinations and save the top item combinations? If not, is there a better algorithm to find strong combinations?
Here's my code, based on everyone's input:
function getAllCombinations(n, k, callback)
{
var iterate = function(remaining, args)
{
var len = args.length;
for (var i = args[len - 1]; i < n; i++)
{
args.splice(len);
args[len - 1] = i;
if (remaining)
{
args.push(i);
iterate(remaining - 1, args);
}
else
{
callback.apply(null, args);
}
}
}
iterate(k - 1, [0]);
}
var itemsCount = 25;
var itemSlots = 6;
getAllCombinations(itemsCount, itemSlots, function(a, b, c, d, e, f)
{
// calculateDamage(hero, arguments);
});