|
-
Jan 11th, 2005, 10:55 AM
#1
Thread Starter
Lively Member
Unique combinations 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
Thanks in Advance!
TRIP85
In the game of life, it's not whether you win or lose, it's how drunk you get.
-Homer Simpson
-
Jan 11th, 2005, 01:21 PM
#2
Re: Unique combinations problem
The idea here is to create an array of permutations, this array will double in size:
Code:
permutations = empty array
for each v in value
copy_of_permutations = permutations
for each e in copy_of_permutations
add the value v to the permutation e
permutations = permutations merged with copy_of_permutations
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|