combinations

Selecting items from a list to achieve a sum

I have a list of items that has numeric values and I need to achieve a sum using these items. I need your help to build such an algorithm. Below, there is a sample that describes my problem, written in C#: int sum = 21; List<Item> list = new List<Item>(); list.Add(new Item() { Id = Guid.NewGuid(), Value = 3 }); list.Add(new Item() { Id...

normal integer combination

How many combinbations can be made of the integers 0-9 using 3 digit combinations? ...

combination of combination java

I need to find combination of combination in JAVA. I have for instance 6 students in class. Out of them, I need to create combination of 4 people in group, and for each group I can choose an intimate group of 2. I have to make sure that there are no doubles (order does not matter).! and need to print the 4 people group. However, this...

Algorithm to generate all permutation by selecting some or all charaters

Hello All, I need to generate all permutation of a string with selecting some of the elements. Like if my string is "abc" output would be { a,b,c,ab,ba,ac,ca,bc,cb,abc,acb,bac,bca,cab,cba }. I thought a basic algorithm in which I generate all possible combination of "abc" which are {a,b,c,ab,ac,bc,abc} and then permute all of them. S...

Generating Unique Combinations from a list of possible repeated characters

I am looking to generate combinations from a list of elements. Right now i am using a approach of generating power set. For example to generate combinations from {a,b,c}, i will enumerate 001,010,100 ,101 etc...and take the element for which the corresponding binary index is set to 1. But the problem comes when there are repeated charac...

Generate multiple Strings based on the number of times repeated

I have a straing ab and there is counter array which contains number of times repeated for each charater. Say repeated[a]=2 and repeated[b]=2. Then the possible strings to be generated are ab,aab,aabb,abb. I am looking for solution which will work for moderarelty high input size. Any algorthims for this would be highly helpfull. Thanks ...

Generate a list of length n with m possible elements

Hi there, I need to generate a ton of lists in Python. Every list is of length 13, and I have 4 possible values that can go into each element. These are [1, -1, i, -i], but it could be whatever. Thus I should get 4 * 4 * 4 ... * 4 = 4^13 = 67,108,864 lists, or more generally, m^n, given the info in the subject. I tried the combination...

Combinations from dictionary with list values using Python

I have the following incoming value: variants = { "debug" : ["on", "off"], "locale" : ["de_DE", "en_US", "fr_FR"], ... } I want to process them so I get the following result: combinations = [ [{"debug":"on"},{"locale":"de_DE"}], [{"debug":"on"},{"locale":"en_US"}], [{"debug":"on"},{"locale":"fr_FR"}], [{"debug":"off"},{...

Java: Simple Combination of a set of element of k order

Hi, I have a set of numbers {'1','13','25','32','49',...}, i want to calculate all possible combinations of this numbers of order k. Esample1: set = {'1','5','23','41,'54','63'}; k = 4; Output1: 1 5 23 41 1 5 23 54 1 5 23 63 1 5 41 54 1 5 41 63 1 5 54 63 1 23 41 54 1 23 41 63 1 23 54 63 1 41 54 63 5 23 41 54 5 23 41 63 5 23 54 63 5 ...

Knapsack with items to consider constraint

I have items I1, I2, I3, I4 with weights W1...W4 and Values V1...V4. I want to maximize values with minimum weights. This is a traditional Knapsack. However there is small constraint some items cannot go together. So lets say I2 and I3 cannot go together. Can anyone provide a dynamic programming solution or any other solution for the sam...

Clean up my makefile fragment?

I'm using GNU Make to run scientific data analysis, where we have a bunch of Matlab scripts that ponder some input data and then spit out several files. It does this in a fairly complex way, so I've had to do some nasty Makefile tricks when trying to describe its function to Make. Here's an example: seg_cams_nozero := cam1 cam2 cam3 s...

Generating combinations in Matlab

I use combnk to generate a list of combinations. How can I generate a subset of combinations, which always includes particular values. For example, for combnk(1:10, 2) I only need combinations which contain 3 and/or 5. Is there a quick way to do this? ...

Output each combination of an array of numbers with javascript

I have several numbers in an array var numArr = [1, 3, 5, 9]; I want to cycle through that array and multiply every unique 3 number combination as follows: 1 * 3 * 5 = 1 * 3 * 9 = 1 * 5 * 9 = 3 * 5 * 9 = Then return an array of all the calculations var ansArr = [15,27,45,135]; Anyone have an elegant solution? Thanks in advanc...