Tough Combinations Or Permutation Or Tree Or Subset Question
Allright. this one is getting to me now. I have a table that shows the neighbors of a cell. For example, my subject is ID 0. for ID 0 i have possible neighbors with IDS 48 498. Now I have a group of neighbor combinations i.e 0 48 and 0 498 and 0 48 498. Next i go to neighbors of ID 48. 48 has 3 neighbors first is ofcourse 0 and the other two are ID 498 and ID 23. Using ID 48 neighbors we get following set: 48 0; 48 498; 48 23; 48 498 23; 48 0 23 etc ettc. Now we also need our main subject ID 0 we now have the following possible combinations (including the original). i.e exclude anything that
[0 48; 0 498; 0 48 498; 0 48 23 (i.e since 498 is already included in original listi have to exclude it for this list).
I need to keep doing this recursively till i run out of neighbors. How would I accomplish this? I do have an exit in the sense that I have to evaluate values for a particular field for these neighbors and when that value crosses 35 i can exit and move to the next row.
I hope I have explained properly.
Thanks
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Combinations/permutations: All Combinations Of N Samples From Population Of M
pardon if there's something on this site that I haven't found. i want to create combinations, one at a time so I can evaluate the combination, then create the second combination and evaluate it, and so on. typically, i'll be working with n=500 or less and m=100000 or less. The values are stored in arrays, so i want to make combinations of indexes not contents. and then store the indexes for a single combination in another array. I want to do this while avoiding calculating how many combinations are possible; the numbers get too big.
Thanks
all combinations of two samples from a set of four samples: l1, l2, l3, l4
l1, l2
l1, l3
l1, l4
l2, l1
l2, l3
l2, l4
l3, l1
l3, l2
l3, l4
l4, l1
l4, l2
l4, l3
all combinations of three samples from a set of four samples: l1, l2, l3, l4
l1, l2, l3
l1, l2, l4
l1, l3, l2
l1, l3, l4
l1, l4, l2
l1, l4, l3
l2, l1, l3
l2, l1, l4
l2, l3, l1
l2, l3, l4
l2, l4, l1
l2, l4, l3
l3, l1, l2
l3, l1, l4
l3, l2, l1
l3, l2, l4
l3, l4, l1
l3, l4, l2
l4, l1, l2
l4, l1, l3
l4, l2, l1
l4, l2, l3
l4, l3, l1
l4, l3, l2
Best Subset Method
I have a database that has several objects (call them computers for this case). Each computer has a different set of support "items." The list is somewhat large (>3000 Computers and >10,000 items).
I would like to be able to pass in a list of items and find the smallest set of computers that support ALL of the times.
Suppose the data looks like:
1ACFGH
2D
3ABC
4EFGH
Suppose you want to support ABCDEFGH
Approach #1 
Check the number of items from your list that each computer supports.
In this case, C1 supports 5, so remove ACFGH from your list and C1 from your list and check the rest for the computer that best supports BDE.
C2,C3,C4 all support only 1 of the remaining items. As a result, this approach would say I would need to use C's 14 to support all of my items.
However, as you look above, you can see that the smallest subset is actually C's 24.
Is there a way to determine that C's 24 are the best fit?
Also, if a C has Items that are not on the list, it doesn't matter. For example, if we wanted ABCDEFG in the above example, C1 would still be the biggest hitter since it handles 4 of the 7 items.
Thanks in advance.
Nate
Subset Of Collection
How can I take a collection of 1000 items and have various subsets of it attached to other objects? For example:
Say a school has 1000 students. This is what I want to do:
School.students (count of 1000)
school.class("English 101").students (count of 50)
One such student can thus be retrieved through 2 objects:
? school.students(studentID).fname
John
? school.class("English 101").students(studentID).fname
John
but it must be the same student, so that if I assign a new name to one of the objects:
school.class("English 101").students(studentID).fname = "WILLIAM"
I want the assignment to affect all other references:
? school.students(studentID).fname
WILLIAM
I know that I must instantiate all 1000 students, and that all other references to those students will be a memory assignment (set thisStudents = students)  But how do I create the SUBSET? Thanks in advance.
Remove Subset From Range
I have a table of data with headings and I would like to remove some of the rows. I have data for about 10 different departments, but I want to remove data for all except one dept.
Here is the "algorithm" I'm planning to use:
1. Sort by dept.
2. Find the dept I want.
3. Remove all rows above (if any) exept row 1.
4. Remove all rows below (if any).
It's something I'll be using on a daily basis, so I would like it to be as simple and as fast as possible. The above algorithm might look pretty simple, but it is pretty involved if you look at the code required. There must be a better way to do this. Any help would be appreciated.
Sort Subset Of Records
Is it possible to sort another table using a sorted subset of records in order to filter on that other table.
DbProgrammer
Looping Through Data Subset
hi
I have the following query:
select sum(iunits) as iunits,sum(ivalue) as ivalue,sum(ivolume)as ivolume,sum(ivolumeHL) as ivolumehl ,periodid as periodid ,productid as productid, tbstores.storeid as storeid
from tbstoredata inner join tbstores on tbstoredata.storeid = tbstores.storeid
where tbstoredata.uploadid = 111 group by tbstores.storeid,periodid,parentid,productid
This returns multiple rows of data. I want to loop through each row, extract 2 values and see if they exist in another table. I need to do this in Query Analyser.
Can anyone please help!
Thanking you in advance
E55
How To Hide MSHFlexgrid Subset Rows
hi guys,
i am using mshflexgrid in my application. i am using shape command and it works fine. but i want to give it realistic look. the one generated by vb is not like the one in MSAccess. In access you can see the hierarchical flexgrid of a PrimarySecondary tables in a good way. i wanted to give my application also the same feel.
so i used another mshflexgrid which will again retrieve only the child but the height setting of the main flexgrid is not getting accurate because i cannot set the height of the subset to 0.
i'll put my problem in simple words. i want to make my subset rows height to 0.(of band 1 in example). see the picture..
 Kishore...
Permutation
I have to display all the permutation of n numbers.
For example for the first three number (1,2,3) they are:
123,132,213,231,312,321.
The number of permutation for n numbers is n!
Is there an algoritm for this use?
Thanks for your answer
MSDN Library  VB Active Subset Misssing?
Hello there,
I have a strange problem:
When I try to use help files in VB 6 ( I have MSDN Library 6.0a installed and it has worked in the past) I do not have the option of selecting VB documentation in the active subset combobox. It seems as though the entire vb help file has disappeared.
I have tried to reinstrall MSDN which didn't work, then I tried to reinstall all of visual studio and msdn and still doesn't work. Can someone shed some light on this for me, I'm getting desperate.
Thank you for your help
How To Extract A Subset Of Nodes From An XML Document As A String?
Is there a way to extract a whole section of an xml document as a
string using DOM?
I am using VB6 and DOM 3 (I am open to other XML technologies but I
have to use VB6). If I have a document:
<Servers>
<Server name="test1">
<Location>Detroit</Location>
</Server>
</Servers>
I want to get back:
Dim s As String
s = "<Server name="test1"><Location>Detroit</Location></Server>"
All of the definitions online for documentFragment seem to say this is
possible, yet all of the associated examples only show how to INSERT a
docFrag into an existing XML document, amd I want to EXTRACT one.
I realize I could parse the whole thing out and write it out to a
string by hand. I just wanted to make sure I'm not missing out on
anything obvious, save the trouble of writing an extra function to do
this.
Thanks
Permutation ?: Please Help A Newbie
I'm VERY NEW to VB. I'm generating a matrix of all possible feature sets for a new product. I'm using Excel to track the material cost and add'l overhead of each feature.
Here's the scenario:
I have six categories of features. They have varying numbers of items within them.
Category 1: 1,2,3,4
Category 2: 5,6,7
Category 3: 8,9,10
Category 4: 11,12,13
Category 5: 14,15
Category 6: 16,17
From each category, I must select exactly one item. I seek to generate a list of ALL possible options.
For Example:
Model 1: 1/5/8/11/14/16
Model 2: 2/5/8/11/14/16
Model 3: 3/5/8/11/14/16
et cetera
Any ideas? Any help would be GREATLY appreciated.
My Permutation Algorithm. Nearly There!
I tried to do it recursively before but that didn't work. Here's a graphical solution that nearly works.. can someone please read through and fix any logic problems? It's definitely on the verge of working!
Permutation Problems . . .
Hey all, it's been a while, but I'm back to working in VB. Now, sure enough, I've got another problem.
I'm writing a little program that will write all possible permutations of the given characters to a text file. The problem is, when I specify a minimum number of characters per line, and have more than one given character, a loop occurs. I have to forcefully shutdown the program, and the generated text file displays the same sequence of numbers over and over again . . .
Here's the code I use for calculating permutations:
Code:
txtMin is the minimum number of chars a line,
txtMax is the maximum number of chars a line,
and txtChars is a textbox containing all applicable characters.
Private Sub cmdCalculate_Click()
For tempvar = 1 To 20
Letter(tempvar) = Left$(txtChars.Text, 1)
LetterPosition(tempvar) = 1
Next tempvar
NumOfPerms = 0
Set A = CreateObject("Scripting.FileSystemObject")
Set Text = A.CreateTextFile(OutputFile, True)
For NumDigits = 1 To (Val(txtMax.Text)  Val(txtMin.Text))
finished = False
Do Until finished = True
LetterSequence = Empty
For tempvar = 1 To NumDigits
LetterSequence = LetterSequence + Letter(tempvar)
Next tempvar
Text.writeline LetterSequence: NumOfPerms = NumOfPerms + 1
For tempvar = 1 To NumDigits
If Letter(tempvar) <> Right$(txtChars.Text, 1) Then Exit For
If tempvar = NumDigits Then finished = True
Next tempvar
If chkBGprocesses.Value = 1 Then DoEvents
LetterPosition(NumDigits) = LetterPosition(NumDigits) + 1
If LetterPosition(NumDigits) = Len(txtChars.Text) + 1 Then
LetterPosition(NumDigits) = 1
For tempvar = 1 To (NumDigits  Val(txtMin.Text))
LetterPosition(NumDigits  tempvar) = LetterPosition(NumDigits  tempvar) + 1
If LetterPosition(NumDigits  tempvar) = Len(txtChars.Text) + 1 Then
LetterPosition(NumDigits  tempvar) = 1
Else
Exit For
End If
Next tempvar
End If
For tempvar = Val(txtMin.Text) To NumDigits
Letter(tempvar) = Mid$(txtChars.Text, LetterPosition(tempvar), 1)
Next tempvar
Loop
Next NumDigits
Text.Close
MsgBox Str$(NumOfPerms) + " permutations derived."
End Sub
Can anyone see what the problem might be?
By the way, it works fine when I have a minimum of one, which makes me think that it has something to do with someplace that "Val(txtMin.Text)" is used. But as of yet I haven't been able to find the bug.
Arigato,
Gamer X
Permutation Algorithm
Hi
I am trying to work out a way to code a vba function that would accept an array of variables, for instance say a list of 20 names, from which you would input a number, say perhaps 5. And on this basis the function would generate a list of permutations based on all the possible combinations of 5 people from the list of 20. Is there some form of algorithm I should perhaps look at, or maybe it is more simple than I think it is.
Any help or pushes in the right direction would be greatly appreciated.
Array Permutation
I've searched the forum, i suppose you call this 'anagram', but all the examples i've found on this forum is with letters/strings
I have to do it with numbers, for example;
i have an array like this
Array(3,7,6)
and i want to find it's combinations
3,7,6
3,6,7
6,7,3
6,3,7
7,3,6
7,6,3
I want to write a routine to do this, but i don't know how to do it or how to modify the examples on this forum
the array's dimension is variable, for example it can be
Array(1,4,7,3,9)
Array Permutation
hi,
i have a tricky problem. i have for example three arrays of different dimestion
A =[1,2,3,4]
B=[5,6,7]
C=[8,9]
i would like to generate all the different combinations of values in these arrays and the values inside the array should not be repeated.
e.g. the resultset should be
1,5,8
2,5,8
3,5,8
4,5,8
1,6,8
2,6,8
3,6,8
4,6,8
1,7,8
2,7,8
3,7,8
4,7,8
1,5,9
2,5,9
3,5,9
4,5,9
1,6,9
2,6,9
3,6,9
4,6,9
1,7,9
2,7,9
3,7,9
4,7,9
any idea how to do this for any number N of arrays?
Thanks!!
Number Permutation
hi,
let say i have a number : 1234 , in this number, it can group to 1243, 1324, 1423, 1342 ... in 24 groups,
any formula to do this?
Combination / Permutation
How could I go about finding every different permutation of a string possible? Like, I want to be able to go through each possibility of a scrambled string:
Example:
abc goes to
abc, acb, bac, bca, cab, cba
All help is appreciated! Thanks!
Permutation Program
Hi! I am not good with math and I am making a permutation program. I am trying to list all the possible permutation in a listview but i am having trouble with the combination.. specifically how to swap the numbers. i am using the same concept as the one i read about in this link http://codeguru.earthweb.com/vb/gen/vb_misc/algorithms/article.php/c5591 but this program uses notepad can anyone help me with this?
Working With Tabletype Recordsets Using DAO In VB6. How To Browse A Subset Using MSFlexGrid
I have a fairly large music database (about 250,000 records, converted from Clipper). To let the user home in on a part of the database (indexed by Artist plus title), I open it as a tabletype recordset, and then use the seek method to locate a part of the table. This works fine.
I then want to let the user browse these records, perhaps up to 70 or 80, which occur consecutively in the table with this index. To do this, I set up a data control for MSFlexGrid to use as its record source. If I set the record source for the data control to something like :
"SELECT * FROM MYTABLE WHERE Artist = 'WILLIAMS'",
that certainly does the trick, but it takes an age (more than 30 seconds), presumably because the index is not being used.
Is it possible to make the record source for a MSFlexGrid (via the Data Control, which I believe I have to use) work efficiently off a section of a table, using the index.
(I imagine that I could get round the problem by reading the section of the table in code and creating a temporary recordset for the FlexGrid, but that doesn't seem to be using the power of the VB controls!)
Thank you for any thoughts on the matter, even if you tell me I am setting about things the wrong way! I really would prefer to stick with DAO for the present, though.
Andrew Mozley
Get The Permutation Of Of 4Digit Number
Thanks for reading below scenario:
It's about generate / get the permutation of 4 digit number .Example:
user will input 4digit number at a text box, assume use input> 1116
and there's command button, when you click on it, it will find the permutatiion of 1116 and display it at a label> 1116 1161 1611 6111
Thank's for any help
Having Difficulties With Permutation Function
Maybe its late in the day but I cant see how to do this. Ignore the actual application for this code but if anyone can help me come up with a function which will just output to the immediate window I can integrate it into the classes it needs to be in later (and of course I will be very greatfull).
The function has 2 inputs, 2 equal length strings of different charecters. I need to obtain every permutation in the correct order of the 2 strings
So if the inputs were "AB" and "CD", I would like to see the following output:
"AB"
"AD"
"CB"
"CD"
A 3 charecter example should produce the following results.
Inputs "ABC" and "DEF"
Results:
ABC
DBC
AEC
ABF
DEC
AEF
DBF
There may be more results that I didnt spot.
I hope ive explained myself properly, any help much appreciated.
4 Digit Permutation Out Of 5 Or More Numbers
I had seen lots of permutation example that generate out of 4 different numbers and it works perfectly well. But I need to generate a 4 digit permutation out of 5 or more different numbers.
Example: I got 5 number: 4,3,2,7,8 and I want some thing like this. 2347,8743,3247,8437,2378!
OR
I got 6 number: 4,3,2,7,8,1 and I want some thing like this. 2317,8743,3217,8437,2378,1287,7128!
No matter how many numbers I have, I Only want 4 digit permutation.
Any ideas?
Permutation Array Algorithm
Hi
I need generate all permutation array when the user type n ( n is natural number >0). When The user type for example n=4
I fill the first row and first column with the sequence {1,2,3,4}, if he typed n= 5 I fill with {1,2,3,4,5}
Example: for n=4
* 1234
+
1 1234  First row
2 2143
3 3412
4 4321
The number in the top and left are number of columns and rows . Look that First row is 1,2,3,4
and first column is 1,2,3,4
In the second column and row I have generate all
permutation possible, but the number only can to be one time in the column and one time in the row. ( the number 1 only one time in the column 1 , one time in the column 2 ...etc).
Other solution for n=4 is
* 1234
+
1 1234
2 2341
3 3412
4 4123
do somebody to know the algorithm that generate all
permutation possible without that number show more than one time in the column and row ?
I search abou derangement algorithm but I do not found.
I have to do this program in C or C++ or Pascal or Visual Basic
Thank You in Advance
INCOMPLETE: PERMUTATION OF LETTERS
im havng a problem figuring out how to extract all possible string combination with length n from a set of string... sori if im confusing here's an example
say collection {a,b,c,d} will produce
a
b
c
d
ab
ac
ad
ba
bc
bd
ca
cb
cd
abc
abd
acb
acd
untill abcd
pls help
Edited by  kmarfilla on 7/6/2006 11:24:20 PM
Pulling Small Subset Of Data From Large Source In Sorted Order.
Hello,
Im having a large performance problem and I need to rewrite a very important part of my front end.
Heres my problem.
I pull a set of data... say the top 50 records of a 500,000 record table. once the user scrolls through that top 50 via a listview control it repolls the database to get the NEXT 50 records... (should the user decide then to go back UP the program queiries again for the 50 records before the current 50)
What I do when I have these chunks of data is just completley reload the list view and highlight the first or last record (Depending on what direction the user is "Scrolling"
THe problem is the dataset has to be sorted by whatever criteria the user has selected... SO.. what I do is simple (Yet horribly slow)
I do the query based on the sort, then I put that data into a temp table so I can have the id of the record. so I can mathmaticly sort through that.
I.E. if I had a table with 10 records numbered 1..10 but sorted on say last name It could not go in numerical order.
Code:
tblData
UserID  Name  LName

1  John  Williams
2  Jessica  Bryan
3  Bethany  Jackson
etc etc
So the sort could be... by last name the ID's would be in 2,3,1 or by first name 3,2,1 or by ID 1,2,3 or whatever.
So what my temp table does is provide me a reference point that I can say..
Give me the top 20 records where the TEMPTable ID is less than... whatever. and that gives me the results.
But like I said it is horribly horribly slow as every time it does this it has to sort a 500,000 record table.. put it in the temp table (Even though I only use a created identy column and the PK identity from the source table) and THEN pull the data for ID whatever to whatever.
Is there a simpler way and MUCH MUCH more efficient way to do this? I tried throwing ram at the SQL server (It now has 4 gigs in it) but that didnt even seem to help in the least.
I'm pretty desperate here.
Combination/permutation Type Problem
Hello everyone
I write software where i have to display catogories on a screen (menus on a tv screen) that a user can navigate through. Currently i am implemnting new functionality that involves subscription based categories, so that only certain people who are entitled can view a particular category. There can be any number of subscription categories configured and the people should only see on the screen the cateogries that they are entitled to enter. So i need to create a screen for each unigue possible combination of these subscription cateogires on the screen.
So if i have 5 subscription categories configured, that means that i have (2 ^ 5)  1 or 31 unique combinations of categories. If the category IDs are 10, 20, 30, 40, and 50 then these would be the 31 unique combinations:
(10,,,,)
(10,20,,,)
(10,,30,,)
(10,,,40,)
(10,,,,50)
(10,20,,,)
(10,20,30,,)
(10,20,,40,)
(10,20,,,50)
(10,20,30,40,)
(10,20,30,,50)
(10,20,30,40,)
(10,20,30,40,50)
(10,,30,40,)
(10,,30,40,50)
(10,,,40,50)
(,20,,,)
(,20,30,,)
(,20,,40,)
(,20,,,50)
(,20,30,40,)
(,20,30,,50)
(,20,30,40,50)
(,20,,40,50)
(,,30,,)
(,,30,40,)
(,,30,,50)
(,,30,40,50)
(,,,40,)
(,,,40,50)
(,,,,50)
The problem that i am having is how to figure out these combinations through code. For some reason my mind is drawing a complete blank today. I would greatly appreciate any help with this problem.
Thanks,
Brian
Permutation Function  Urgent ** Resolved
Hi all,
I Know what permutation & I know how to do this. But the thing is I am struggling to make it as a redursive function. Can anybody help me by providing some code which uses recursive logic to produce permutation for n digits.
I have an ex for 4 digit permutation without recursion. I request you people to pl convert this for n numbers in a recursive manner.
VB Code:
Dim I As Integer, J As Integer, K As Integer, L As IntegerFor I = 1 To 4 For J = 1 To 4 If Not (I = J) Then For K = 1 To 4 If Not (K = J Or K = I) Then For L = 1 To 4 If Not (L = I Or L = J Or L = K) Then Print I; J; K; L Next L End If Next K End If Next JNext I
How To Collaps A Tree Node With Children And Have It Clear The Children (Tree.Nodes.Remove
Hi,
I have a tree that has topics, so for example in the following:
Aouto type
Car
Suv
Sports car
Van
Truck
Motor cycle
Aircraft
Helo
Jet
Plain
I notice that If I colllaps a level it still is retaining the children structor in memory, where the first time through it builds them.
I need that if I collapse the car node it to totaly clears its children and rebuild them again on expansion. Is there a tree function or something that would do this? I think the answer is in using Tree.Nodes.Remove some how, but I am not sure how I would use it here.
Thank you
Edited by  itmasterw on 6/23/2006 8:12:29 AM
Combinations
hi,
i'm trying to generate all possible combinations of a string but don't seem to get it right  this is what i want to do:
String: "ABC"
Result list:
ABC
BCA
BAC
CAB
CBA
Any response would be appreciated
Regards,
Bert
Combinations?
I'm trying to write some code that can select all combinations of a certain number of values from an array.
ie. taking a certain (user defined) number of cards from a deck and finding all possible combinations.
Note: The order of the items does not matter.
Any help welcome, thanks.
Key Combinations
hi again
first of all, i'm using:
form1.visible = false
in form_load
....
however, i want a key combination (f12 and shift preferably) to show the form.....
Combinations...
Hello all, I ask for input for 6 numbers and I need to calculate all the possible 4 digit combinations using that number, how would I do this?
All Possible Combinations
I'm having some trouble trying to code a function and hoping someone has done this before or has an idea of where to start.
lstItems.list contains 32 items
Item1
Item2
Item3
Item4
Item5
Item6
through
Item30
Item31
Item32
I need to find all possible combinations but there are a couple requirements. Item1 and Item2 must be included but location in the string does not matter.
Examples:
Item1, Item2, Item29, Item21, Item16
Item2, Item1, Item29, Item21, Item16
Item25, Item11, Item1, Item7, Item2
After I run it and get all possible combinations with 5 items I also need to be able to change it to 6 items and get all possible combinations of 6 items, then 7 items and so on.
Any help or ideas appreciated. Thanks.
If making Item1 and Item2 mandatory is complicated it can be skipped and just get all possible combinations of the list.
Update: Well I did kind of get this done a sloppy way by looping 1mil times saving all results then deduping the file then removing the lines that didn't have item1 and item2. I assume I got all results this way but of course no way to guarantee it. Would still love to see a clean function that does it properly.
ALL Possible Combinations
hi to all,
i have text1.text and text2.text , datagrid1 and command1 button
i want to put any number to text1.text and any number to text2.text
and view all possible combinationsbetween theese numbers to datagrid1... is that possible ???
thanks for your time
All The Possible Combinations
Hello,
I was wonding how to generate all the possible combinations of a group of 6 1digit numbers. For example 1,2,3,4,5,6 Could be 123456, 234561, 345612, so on.
Thanks for the help
Key Combinations
I know people ask this all the time but there are so many different ways I just want to find the most convenient one possible.
I have use that GetAsyncKeyState but can't get it to work the way I want. I just want a code were Alt + Ctrl + E or Win + G will launch, hide, or activate things in a program.
Not having working HotKeys or Combinations on my app's has been bugging me for a wile, I would appreciate it if someone could tell me how.
Thanks Alot,
...:::ONE:::...
Combinations
Can someone plz tell me how I would work out all the different combinations in the Lottery. Thanks
Combinations
Hello,
I've really been struggling with the following problem for a couple of days and I'd appreciate any suggestions any of you may have...
I have an object that can have up to 4 properties. The object represents a general Product that we are selling in our store, and the properties are used to differentiate the products. For example...
Product Object: Men's Shirt
Property 1: Size (Small, Medium, Large)
Property 2: Color (Red, Blue, Black)
Property 3: Type (Tshirt, Sweater, Hooded)
Property 4: InStock (Yes, No)
The properties are not the same for each product and can be changed by the user to reflect the properties of different products as needed. For example...
Product Object: Custom Baseball Cap
Property 1: Adjustible Fit (Yes, No)
Property 2: Logo  Designed by the customer
Property 3: InStock (Yes,No)
The above baseball hat comes in only 1 color and 1 size so it does not need to have a Size or Color property. The logo is designed by the customer.
For inventory purposes, I need a way to find a way to obtain all combinations of properties for a give object...
Code:
Product Size Color Type InStock
Men's Shirt Small Red Shirt Yes
Men's Shirt Small Red Shirt No
Men's Shirt Small Red Sweater Yes
etc...
I've been looking into combinations and permutations, which I believe would work except for the fact that sometimes a Property may not be used by a product. It is easy enough to put every value of each property into an array and loop through each one...
Code:
for int1 = 0 to ubound(arrProperty1)
for int2 = 0 to ubound(arrProperty2)
for int3 = 0 to ubound(arrProperty3)
for int4 = 0 to ubound(arrPropery4)
'process this unique combination...
str1=arrProperty1(int1)
str2=arrProperty2(int2)
str3=arrProperty3(int3)
str4=arrProperty4(int4)
next
next
next
next
I think that the above solution would work if I always knew that every object had 4 properties, but how would I do it if an object has less than 4 properties. Also, it is possible for Property 1 to be undefined, but Properties 2, 3, and 4 are in use. Or it is possible that Property 2 and 3 are defined for an object but 1 and 2 are not, etc...
I'd appreciate any insight in the matter or a push in the right direction. I'd be glad to elaborate if more information is required.
KEY Combinations...
How do I find that someone has pressed,
Ctrl + Alt + Shift + W in a textbox...
Cheers...
Combinations...
Does anyone have any code for doing combinations in VB.net or visual
basic ? I'd like to
be able to get an array of combinations (not permutations) of words from a
base group of words while specifying the number of unique words to be used
in the result set.
For instance if I have the set {cat dog fish snake} I'd like to be able
to get back a result array of all possible combinations (not permutations)
of X number of words from my base set. For example, all possible
combinations of any 3 words from the base set above would be :
{cat dog fish}
{cat dog snake}
{cat fish snake}
{dog fish snake}
Ideally, I would like to be able to get a result array back with Y known
words in it. For example, if I wanted all possible combinations of any 3
words from the base set above again, but this time I only wanted resulting
arrays that contained the words cat and snake the resulting array should
look like:
{cat dog snake}
{cat fish snake}
Anybody seen this code or at least the mathematical formulas needed to
implement it?
Thanks!
All Possible Combinations...
Hi everyone,
I'm looking for a piece of code that outputs all possible combinations of the characters abcdefghijklmnopqrstuvwxyzABCEFGHIJKLMNOPRQRSTUVWXYZ0123456789 in a string of definable length (e.g. 6 letters).
Any idea how to do it efficiently?
I'm sure it only takes a few lines...
Thanks for your help!
TS
String Combinations
Hi, I was wondering how i would use a for loop to cycle through all possible combinations of a 32 character string, that includes az,AZ,09. I googled but couldn't find anything on this, any help
Number Of Possible Combinations
Hiya,
I am a newcomer to programming and really stuck!!! Any help would be gratefully received if you can as i know it is a hard question!!
I have written a program that gives me all possible combinations for 1 and 2 for a length of 60 digits but is taking for ever to run.
My problems are that the number of 1’s and 2’s must be equal, thirty 1’s and thirty 2’s in every possible combination.
For instance
11111111111111111111111111111122222222222222222222 2222222222
or
12121212121212121212121212121212121212121212121212 1212121212
And so on
Thank you
Suzie
Combinations, Permutations
I have a list of 24 items. For example, boat, chair, table, etc.
I want to find and list all possible combinations of any two(2) of them, and order does matter.
Any suggestions or VB code I can use to automate the process?
Thanks.
Permutations && Combinations
I've been playing around with perm/comb processing, and got some things to share.
following is a slight improvement of a method posted by MathImagics for calculating nCr (the number of ways to select r items from a total of n):
Code:
'calculates n!/(r!*(nr)!), avoids overflow by scaling down the multiplied values
Function nCr(n As Long, r As Long) As Variant
Dim Numerator&(), Denominator&, iNumerators&, GCD&, i&
'if the number of items equals slots, or there are no slots
If (n = r) Or (r = 0) Then
'there is only only combination
nCr = CDec(1)
'if the number of item is 1 more then the slots, or there's only 1 slot
ElseIf (n = r  1) Or (r = 1) Then
'there are n possibilities
nCr = CDec(n)
Else
'get the smaller of r/nr
iNumerators = n  r
If r < iNumerators Then
r = iNumerators
iNumerators = n  r
End If
'populate an array with values from r+1 to n
ReDim Numerator(1 To iNumerators)
For i = 1 To c
Numerator(i) = i + r
Next i
'for each denominator
For i = 2 To iNumerators
n = 1
Denominator = i
'loop through the numerators
Do
If Numerator(n) > 1 Then
'if there's a common divisor
GCD = GreatestCommonDivisor(Numerator(n), Denominator)
If GCD > 1 Then
'scale down the numerator
Numerator(n) = Numerator(n) / GCD
If GCD = Denominator Then
Exit Do
'there's more to scale down from the denominator
Else
Denominator = Denominator / GCD
End If
End If
End If
n = n + 1
If n > iNumerators Then Exit Do
Loop
Next i
'multiply the numerators, an error should only be caused by overflow
On Error GoTo ErrorOverflow
nCr = CDec(Numerator(1))
For i = 2 To iNumerators
nCr = nCr * Numerator(i)
Next i
End If
'calculation didn't overflow
Exit Function
ErrorOverflow:
'the result is just too big
MsgBox n & "C" & r & " overflows", vbExclamation, App.Title
End Function
this has the same functionality as a standard scientific calculator.
the main part that differs from MathImagic's code is that I don't store the entire Denominator list,
and instead I iterate it dynamically canceling them one by one.
another algorithm I came up with, handles rotating permutations when selecting a number of items from an item range (not all of them...):
Code:
'Variables
Private PWheel() As Long
Private LB As Long, MB As Long, UB As Long
Private PCount As Variant
Private iStep() As Long
'Initialize the rotation with new bounds
Public Sub Init(LowerBound As Long, UpperBound As Long, Slots As Long)
Dim i&
'the upper bound must be larger than the lower
If LowerBound >= UpperBound Then
MsgBox "invalid bounds", vbOKOnly Or vbExclamation, App.Title
ElseIf (1 > Slots) Or (Slots > (UpperBound  LowerBound + 1)) Then
MsgBox "invalid number of slots", vbOKOnly Or vbExclamation, App.Title
Else
'save the bounds for later use
LB = LowerBound
MB = LowerBound + Slots  1
UB = UpperBound
'redim the permutations wheel according to the new bounds
ReDim PWheel(LB To UB)
'populate the permutation array with values from LB to UB
For i = LB To UB
PWheel(i) = i
Next i
'this is a help variable used when rotating the wheel
ReDim iStep(LB To MB)
'determine the number of permutations
'PCount = nPr(UB  LB + 1, Slots)
End If
End Sub
'Rotate the permutation wheel
Public Sub Rotate()
Dim i&, n&, lTemp&()
'permutating one item
If MB = LB Then
If PWheel(LB) = UB Then
PWheel(LB) = LB
Else
PWheel(LB) = PWheel(LB) + 1
End If
'permutating some of the items in the range (this is the algorithm)
ElseIf MB < UB Then
i = MB + 1
Do While PWheel(i) < PWheel(MB)
If i = UB Then
i = MB
Do While PWheel(i) < PWheel(i  1)
i = i  1
If i = LB Then Exit Do
Loop
If i > LB Then
ReDim lTemp(i To MB)
For n = i To MB
lTemp(n) = PWheel(n)
Next n
For n = i To UB  (MB  i + 1)
PWheel(n) = PWheel(n + (MB  i + 1))
Next n
For n = UB  (MB  i) To UB
PWheel(n) = lTemp(UB + i  n)
Next n
SwapLongs PWheel(i  1), PWheel(i + iStep(i))
If iStep(i) + i = UB Then
iStep(i) = 0
Else
iStep(i) = iStep(i) + 1
End If
Else
For i = LB To UB
PWheel(i) = i
Next i
End If
Exit Sub
End If
i = i + 1
Loop
SwapLongs PWheel(i), PWheel(MB)
'permutating the entire range _
(same as the method used by MathImagics In the knowledge base)
Else
n = UB  1
Do While PWheel(n) > PWheel(n + 1)
n = n  1
If n < LB Then Exit Do
Loop
If n >= LB Then
i = UB
Do While PWheel(n) > PWheel(i)
If i = LB Then Exit Do
i = i  1
Loop
SwapLongs PWheel(i), PWheel(n)
End If
i = UB
n = n + 1
Do While i > n
SwapLongs PWheel(i), PWheel(n)
i = i  1
n = n + 1
Loop
End If
End Sub
'Retrieves the current permutation
Public Function Current() As Long()
Current = PWheel
ReDim Preserve Current(LB To MB)
End Function
I hope these can be of some use to someone.
Combinations Of Text.
Hi there fab vb people. this is my problem:
i want to generate every combination of words, from a list of words, in a single string.
so, for example, these three words: dog, cat, mouse.
would come out, in the final output, like this:
dog  dog cat  cat dog  dog mouse  mouse dog  cat mouse  mouse cat dog cat mouse  dog mouse cat  cat mouse dog  ... et al.
(excluding the pipes of course, they are only for show
i know that there are millions of combinations. and for a a say...four, or five word input, the output would be very long.
is there a simple algo that would fix this problem?
as my words are listed in a listbox, the code would ahve to pull them out of there, and shot them in a tall edit control.
i'm absolutely stumped, anyone any ideas?
crowe
