Generate Combinations Of Elements Of A List<T> In .NET 4.0?

Jul 13, 2009

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 for a solution that is a) elegant, and b) can be coded in VB10/.Net 4.0.

This means a) solutions requiring LINQ are ok, b) those using the C# "yield" command are not.

The order of the combinations is not important (i.e., lexicographical, Gray-code, what-have-you) and elegance is favored over performance, if the two are in conflict.

(The OCaml and C# solutions here would be perfect, if they could be coded in VB10.)

View 5 Replies


ADVERTISEMENT

.net - Generate All Unique Combinations Of Elements Of A IEnumerable(Of T)?

May 12, 2011

This question is virtually the same as this SO post, only I'm looking for a VB.NET (.NET 4) solution. I've spun my wheels long enough trying to come up with a generic solution to solving this "power set" problem.

Dim choices As IEnumerable(Of String) = {"Coffee", "Tea", "Milk", "Cookies"}
Dim choiceSets = choices.CombineAll()

I'm looking for choiceSets to be an IEnumerable(Of IEnumerable(Of T)) so that I can do something like:

For each choiceSet in choiceSets
Console.WriteLine(String.Join(", ", choiceSet))
Next

[code]...

As you can see, this is every non-repeating combination from the source IEnumerable(Of T) (which could have 1 to many items in it - this example only had 4), it operates based on the order of the items in the source IEnumerable(Of T), and each item in the list is >= the previous item in terms of number of items in the inner IEnumerable(Of T).

For what it's worth, this is not homework; though it sure does feel like it. EDIT: Updated the example so it does not look like the result is alphabetically sorted, to stress that the source IEnumerable(Of T)'s existing order is used and added a 4th choice to clarify the sorting requirement within each set.

View 5 Replies

Make All Possible Sum Combinations From Array Elements In VB

Mar 24, 2010

If there is an array with elements: 1,2,3,4, the program should return another array with sum of all combinations:

1
2
3

[Code]....

View 3 Replies

Generate All Possible 3 Or 4 Digit Combinations?

May 30, 2009

I am trying to generate all possible 3 or 4 digit combinations from 0 to 9. I will be outputting them to a text file but I just need help with actually generating them.

View 7 Replies

Combinations :: Generate All Possible Words On File?

Dec 10, 2011

Example :

If a got word "don" then file will contain
ddd
ddo

[code].....

View 1 Replies

Generate Combinations Of Pixels On A Page?

Mar 25, 2011

how to generate combinations of pixels on a page using 24bit color using MS VB 10.0.

View 1 Replies

How To Generate All Real Combinations From String Array

Apr 2, 2012

I need to generate all combinations (not permutations) in VB .NET, I've been search and all I found is for permutations (some says combinations but when I was try it, all are permutations).

What I need is to generate combinations from string array:
Dim data_array As String() = {"one", "two", "three", "four", "five", "six"}

I need that: If I say just 1 length, it must returns:
one
two
three
four
five
six

If I say 2 length, it must returns:
oneone
onetwo
onethree
onefour
... etc ...
twoone
twotwo
twothree
... etc ...

And continues til end with all combinations. If I say more length do it as well.

View 2 Replies

Generating A List From Combinations?

Aug 3, 2009

I am writing an application in which we have a Product Module, Now instead of defining individual products, we want to just state the Size Ranges in Width, height and different size scale available, and then automatically generate a list of products with all the Size combinations. I cant figure how to do this.Ill give an example.This is how we define a product

Product[code].....

If i had a fixed number of Size types i would just run For loops within for loops and inside the inner most for loop write an Add Item statement with Index of evry selected item, however since the Size types are dynamic, i need to write a recursive loop, and i just cant figure how to.

View 7 Replies

Achieve A List With All Possible Combinations Of Letters?

Sep 9, 2009

I was wondering how to achieve a list with all possible combinations of letters. Now there are some nice examples on the Internet, however, I'd like to have the following:

Let's assume you have 3 letters (A, B, C), and have a limit length of 3, then it should display this list:

A
B
C
AA

[Code].....

Now, this would be fine with recursive calls I think, but I find it really difficult to think how to code that and how the computer will execute the code. It would be easier if all possibilities had a length of 3, but here that isn't the case.

View 30 Replies

VS 2005 : Generate A Strongly Typed Xml Document Object So That One Can Simply Dot Into The Various Data Elements?

Mar 10, 2011

I have a situation where I have an xml document that has a bunch of elements that I basically use as data variables. I populate the variables from various sources and then transform the xml file to an html file for user viewing.having to remember the names of all the data elements in the file is somewhat tedious. Is there a way to generate a strongly typed xml document object so that one can simply dot into the various data elements?

View 5 Replies

Create Local Copy Of A List To Be Able To Change Elements Only In New List?

Oct 26, 2011

This is probably a really basic question - but I have a list of items (custom objects) being passed from one winform (.net 3.5) to another. I want to create a local list to store changes that only get persisted if the user clicks save. Currently if the user clicks cancel - the changes are still applied in the first form because I assume the objects are reference type.I have the save working as it calls a service layer to do the save and then refreshes the other form - but not the cancel.

View 1 Replies

Generate A List Of Random Integer With A Click Of The Button And Put The Results In A List Box Using .Net?

Nov 18, 2009

If I can generate a list of random integer with a click of the button and put the results in a list box using VB.Net but how do I randomly change several integer number generated by button 1 by clicking button 2? How I retain the results of button1 and change the results when clicking button2?I try before but the two button function code cannot relate to one another.

View 1 Replies

Dynamically Generate List Items To An Unordered List In ASP.NET?

Nov 27, 2009

I have an error panel that is subbed in to a page if an error goes wrong to gracefully handle and display errors.Currently, I am just appending the error messages to a string and pushing that to a label. If you have multiple errors, this gets messy.I'd like to push each error to a list item in a bulleted, unordered list.How can I dynamically generate, from a vb codebehind file, new list items inside of an undordered list element?

View 2 Replies

App For Copying Elements From One List To Another?

Mar 11, 2012

I want to copy the elements from one list to another.

View 4 Replies

Getting A List Of Elements To Load?

Apr 11, 2011

I'm Having trouble getting a list of elements to load. The data is defined like this:

Public Class NavEquipmentMgr
Shared M_ps_NavQuit As Boolean
Shared M_ps_No_Nav_Equip As Boolean

[Code].....

View 9 Replies

Re-arranging Elements In List(Of T)?

Apr 7, 2011

I got a list of objects. Each object has a property called Z (integer).There will come a point during run-time I will want to re-arrange such objects in my list depending on their Z property. The objects with lower Z go first in the list, and the ones with higher will go last.I have thought of a couple things, like making a new List, then loop through each object in the original list as many times as the amount of objects such list has (so if it has 10 objects, I would loop 100 times), and each iteration will check the Z values. When a cycle is done (for every 10 iterations), I will remove the object with the lowest Z number in cycle and add it to the new List. And so on until the 100 iterations are done.

View 3 Replies

Remove Elements From A List?

Feb 6, 2010

I have a List of a custom class (barData) that I need to remove elements form based on a date.

The bardata class holds data of stock price information.[cod]e...

Is there a way to do it without looping through each bar as I may have 2000 plus bars for each stock and may have 2000+ plus stocks to look at. It can be done by looping but it is slow.

View 2 Replies

Reflection For A List Properties Elements?

Oct 31, 2010

I am creating a dynamic clone method to be used in my custom classes. I want the clone function to be completely generic, so I do not have to make any changes when I add new properties to the class. I am having an issue with regards to making a deep copy a property that is a List. sample code that will enable me to identify with reflection that a property of my class is a List, and then more importantly the code to loop through the the List elements and copy of each of them. I have been able to identify a property as a List by using the NameSpace of the property type, but I'm not a big fan of that method. Either way, I have yet been able to dynamically loop and deep copy the elements of the property that's a List using reflection.

View 2 Replies

VS 2010 HTML Elements List?

Jan 17, 2012

I'm making a bot to auto-reply to my PMs on a website, and I'd like to get all of the HTML elements with a class name 'InboxRow'. I can get the HTML element one at time, but the problem is that these will be dynamic, so the id and amt. of them will always change, so I want to put them in an array, where I can call each one up and perform the rest of my code for it. I just can't seem to be able to figure out how to find all the HTML elements with the class name and put them in an array, and I can't seem to find any tutorials online

View 4 Replies

.net - Does For Each Acting On A List Always Visit Elements In The Same Order

Nov 4, 2010

Will the elements in myList always be visited in the same order with a For Each loop (assuming I don't alter the list)?

Dim myList As New List(Of MyElement)
....
For Each myElem As MyElement In myList
' yadda yadda yadda
Next

View 1 Replies

.net - Make Array From Properties Of Elements Of List?

Mar 25, 2012

Is there a succint way in vb.net to create an array or similar of each of the properties in a list?

E.g. If I have a list of 'a' and each 'a' has a property 'b', I want to create an array which contains all the 'b's, in the same index positions as the original list.

View 2 Replies

Assign Values To Structure Elements In A List?

Aug 19, 2011

I have a user defined structure in a list that I am trying to change the value for in an individual element within the list of structures. Accessing the element is not a problem. However, the compiler complains

"Expression is a value and therefore cannot be the target of the assignment"when I try to update the value.For example:

Public Structure Person
Dim first as String
Dim last as String
Dim age as Integer

[code]....

View 2 Replies

Setup A List Consisting Of Arrays Of Two Elements?

Feb 27, 2009

I need to set up a list consisting of arrays of two elements. Simple, right?

Like: (code snippet):

Dim strDataPoint(1) As String '2-element array
Dim lBiasCurve As New List(Of strDataPoint) 'list of 2-element arrays
Dim lPwrCurve As New List(Of strDataPoint) 'another list of 2-element arrays

But this gives me an error msg on 2nd and 3rd line: type strDataPoint is not defined....

View 8 Replies

Copying Elements From List Where Frequency Is Custom Class

Sep 21, 2010

I'm trying to copy the elements from a List(Of Frequency) where Frequency is a custom class I have made. Everything in the other places seems alright but the problem seems to be with the copying, where it still references the original table, so changing the values of one changes the original. I've tried the List.CopyTo() method and tried converting to and array with List.ToArray and then using Array.Copy but it seems they always change the original. I've also tried a for loop and create and New instance of the classes but that doesn't work either. What I'm using it for is to pass the List(Of Frequency) to a new Task to do multitasking(), if anyone can think of a better method to pass a List(Of Frequency), or an array to to a task and have it not change the original.

View 3 Replies

Difference Between A Pointer Or A Variable In The Contect Of List Elements?

Apr 25, 2009

Do List's hold the instances of a variable element or just the pointer to the the variable element? My application uses a list of elements, which can be re-ordered at any time, but I need to maintain another list of pointers to those elements, so that the element pointers can be used to access any element irrespective of their order in the main list? the difference between a pointer or a variable in the contect of list elements?

View 16 Replies

Linq To Xml Query Returning A List Of All Child Elements?

Mar 8, 2010

I have got an xml document which looks something like this.

<Root>
<Info>
</Info>
<Info>

[Code]...

How can i write a linqToXML query so that it returns me an IEnumerable containing each child element, in this case all five child elements of , so that i could iterate over them. The order of child elements is not definite, neither is number of times the may appear.

View 1 Replies

Read All Elements And Child Nodes Of XML In A List Using XDocument?

Jul 6, 2011

I have to get all the Entity Source,Entity Target,Property Source and Property Target values in list respectively.[code]...

View 1 Replies

Read The String Which Contains XML Data And Store The Elements In A List?

May 17, 2011

I have a string with xml data.Dim appManifest As String = New System.IO.StreamReader(Application.GetResourceStream(New System.Windows.Resources.StreamResourceInfo(e.Result, Nothing), New Uri("AppManifest.xaml", UriKind.Relative)).Stream).ReadToEnd()

[Code]...

View 2 Replies

Use The RemoveRange Function To Remove A Couple Elements From A List?

Feb 2, 2011

I use the removeRange function to remove a couple elements from a list, but the Count of the list seems to be intact, so I assume it didn't work the way I expected it too.... so, how do you remove elements? I mean, reduce the list's Count value ultimately.

View 3 Replies

Draw Lines Between Elements In 2 List Views To Bind The Data?

Aug 4, 2009

I am using VB 2008 and wonder if there is a way to draw lines between the data elements in two listviews to bind the elements together?

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved