Ruby discrete optimization algorithm for a generic knapsack problem