It sounds like you're trying to solve an intractable problem like the knapsack problem. This type of algorithm becomes extremely painful around n=30 -- there are over a million possibilities to run through at that point.
Comment on Re^2: Turning very larger numbers into an array of bits