Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
The problem description:

I have tree lists (dropdowns, actually) suppose a,b & c , initially having x,y & z number of items respectively.

When i select any option from one of the lists, one of the two things can happen:
a. The options in the other lists remain the same
b. The one or more options in the other lists gets flitered (i.e. removed) from the list
This removal of items is not predictable. Now the user can select an option in the other list, resulting in more filtering, and so on.

Considering that the sequence of selection of matters. I would like to have an algorithm that could get me the ways in which the user can select all possible combiantions from these three lists.

I have thought about this, but did not get any success. Any help would be greatly appreciated!
Posted

1 solution

Just Googling you may find many available Java implementation of a 'permutation algorithm'[^].
However, it looks to me, you have not a clear idea of your own requirements.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 28-Nov-13 3:57am    
Ha-ha, good point, a 5.
—SA
CPallini 28-Nov-13 4:03am    
Thank you, Sergey.
Sabaat Ahmad 28-Nov-13 4:44am    
If you cannot understand what I want to achieve, please don't bother to reply. BTW, I have this application already built
CPallini 28-Nov-13 5:00am    
Sorry for trying to help, probably I misunderstood: 'any help would be appreciated'.
By the way: can you understand what you want to achieve?
Good luck.
Stefan_Lang 28-Nov-13 6:56am    
You shouldn't be so hasty to refute Carlos advice: Your motivation to find all permutations of user choices is unclear. While we don't know your reasons, interacting with a user who makes a serious of choices is a very common pattern, and trying to enumerate all possible permutations of choices is a very odd thing to do in such a context!

You should ask yourself: what do you need these permutations for? And: do you really need to somehow store and organize all permutations at once? Is there an algorithm you wish to perform that requires the full set of permutations?

What's more: is it possible that in the future the user gets to choose from a fourth list - and if so, will you need to build the permutations for all four lists?

Maybe when you think about it you'll realize that you never really need those permutations, at least not the full set.

There is only one scenario I can think of that would require considering all possible user selections: test coverage. But even in that case, it rarely makes sense to actually create a list of all permutations: instead you should strive to split up your tests in a reasonable manner. Also you never actually need to create and maintain a full list of permutations, you only need to enumerate them! That's quite a different and much less complex task.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900