combinations

How to Generate Combinations of Elements of a List<T> in .NET 4.0

I have a question that is similar, but not identical, to the one answered here. I would like a function generate all of the k-combinations of elements from a List of n elements. Note that I am looking for combinations, not permutations, and that we need a solution for varying k (i.e., hard-coding the loops is a no-no). I am looking fo...

Number of combinations in configurator

I have been asked to program a routine to decide the number of possible combinations in a product configurator. The configurator is really simple. Even though it has more features than this, it can be modeled as several "radio groups" (like the UI control) where one of n options has to be selected. The only kind of constraints that can...

Most elegant combinations of elements in F#

One more question about most elegant and simple implementation of element combinations in F#. It should return all combinations of input elements (either List or Sequence). First argument is number of elements in a combination. For example: comb 2 [1;2;2;3];; [[1;2]; [1;2]; [1;3]; [2;2]; [2;3]; [2;3]] ...

Counting binary bit pattern combinations

I'm looking for an algorithm that will count the number of binary bit patterns in an n-bit word which are equal to or less than an arbitrary limit that is less than 2^n. Further, I want to generate the count for all 1-bit combinations, 2-bit combinations, etc.. Obviously, if the limit were 2^n, there would be 2^n combinations (C(n,1) 1-b...

What is an efficient algorithm to create all possible combinations?

Let's say there's n amount of entries, each of whom can take the value of 0 or 1. That means there's 2^n possible combinations of those entries. The number of entries can vary from 1 to 6. How can you create each possible combination as a sequence of numbers (i.e. for n = 2: 00, 01, 10, 11), without resorting to a thousand IFs? ...

C# - LINQ How to return possible combinations list by removing Nulls ?

I have two arrays : string[] Group = { "A", null, "B", null, "C", null }; string[] combination = { "C#", "Java", null, "C++", null }; i wish to return all possible combinations like { {"A","C#"} , {"A","Java"} , {"A",C++"},{"B","C#"},............ } (null should be ignored). using LINQ. Help please. ...

Combinatorics: Building 10 groups of 100 elements while elements remain sorted

Hello! I've got a problem concerning combinatorics. Unfortunately, I can't describe it abstractly so I try to explain it as a story. :) Problem: There are 100 children on the schoolyard. They all have unique heights, assuming the values are 100-199cm. You want to build 10 groups, each consisting of 1-99 children. How can you build al...

Finding all non-conflicting combinations of values from multiple lists of values

I have the following array which contains arrays of values: $array = array( array('1', '2'), array('a', 'b', 'c'), array('x', 'y'), ); There can be any number of arrays and an array can contain any number of values. I currently have a piece of code which will generate all combinations where one value is taken from each arr...

maximum number combinations

I am trying to generate a list of all possible number combinations within a set of four numbers using all numbers from 0 through 9. I'm getting close but the output doesn't show every possible combination starting from 0000 all the way to 9999. Any clues as to why the following code is dropping certain combinations? def permgen(item...

php array combination

I want to generate all combination of length r from a set [0...(n-1)] So the output should be like this (n = 6 r = 2) $res = array(array(0,1),array(0,2),array(0,3),array(0,4),array(0,5),array(1,2),array(1,3),array(1,4),array(1,5),array(2,3),array(2,4),array(2,5),array(3,4),array(3,5),array(4,5)); with a function like function permut...

Algorithm for finding out the cheapst combination

Hello, I have a few sets which are like SET A(1,2,3,11,10) - $30 SET B(2,5,8) - $20 SET C(6) -$25 SET D(6,8) -$30 SET E(7,5) -$20 SET F(5,6,7,8,9,10) -$60 . . . and so on... All are random, Now consider sets D,E and F I want to buy the cheapest combination for a set, SET Q(7,8,6,5) the answer ...

All possible combinations of elements

Hi, I'd like to know a possible algorithm to calculate all possible combinations, without repetitions, starting from length=1 until lenght=N of N elements. Example: Elements: 1, 2, 3. Output: 1 2 3 12 13 23 123 ...

How do I generate integer partitions?

I have a list of numbers like 1,2,3 and I want to find all the combination patterns that sum up to a particular number like 5. For example: Sum=5 Numbers:1,2,3 Patterns: 1 1 1 1 1 1 1 1 2 1 1 3 1 2 2 2 3 You're allowed to repeat numbers as far as they don't go over your sum. Which way would be best to program this? ...

Keystroke combinations in c# winforms app

Hi, does anyone know how i can setup an event handler so that if the keystrokes Alt + Shift + Ctrl + a letter will do something? ...

combination of a two array (ruby)

Hi , What is the ruby way to achieve following? Thanks. a = [1,2] b = [3,4] I want an array: => [f(1,3) ,f(1,4) , f(2,3) ,f(2,4)] EDIT: Sepp2k's way is very clever and impressive but Aaron used build-in function. I accept the build-in method as the answer. Thanks you all! ...

combination of a two array ( vector )

Hi, I have v1 and v2 , how should I got a new v like below? v1 = {1,2} v2 = {3,4,5} v = {f(1,3) , f(1,4) , f(1,5) f(2,3) ,f(2,4) ,f(2,5)} I know I could do it using two loops, But If there is more idiomatic way like using STL algorithm? //using two loops for iter1 of v1 for iter2 of v2 v.push_back(f(v1,v2)) EDIT...

Linq Arithemetic Operator combinations

When attemptiing to solve the below assignment : Using the Arithmetic operators ( +,-,*,/) rearrange four fives to equal the number 1 to 10. Example : 5/5+5-5 =1 ,5/5+5/5=2 I tried in C# without using Linq (I don't know how to proceed further) public void GetDetails() { char[] sym = new char[] { '+', '-', '/', '*' }; ...

Combinations with replacements

Hey. I know how to generate combinations of a set and that's a builtin in Python (what I use), anyway. But how to generate combinations with replacements? Suppose I have a set with, say, two identical elements - for example, "AABCDE". Combinations of 3 items could be: "AAB" "ABC" "CDE" However, the program would count 'ABC' twice - ...

intelligently generating combinations of combinations

Let's say I have a class of 30 students and want generate every possible way in which they can be partitioned into groups of 5 (order is irrelevant). I know how to find all the combinations of students to form one group individually (http://www.merriampark.com/comb.htm). By using that iterator and some recursion, I can find PERMUTATIONS...

Any way of getting a set of all set pairs in Java?

Let's say I have a set with the following values: A, B, C, D. Is there an easy way of getting a set that contains AB, AC, AD, BC, BD, CD? In Ruby, I can do this directly with the combination function. Any suggestions on how to do this in Java? ...