Solved
Permutations of multiple string arrays' elements
Posted on 2003-12-10
I am working on an insurance system web app. The system allows users to set up price quotes based on a number of factors. The quotes must be made for all combinations of selected factors. So, if I’m making a quote, the factors that I choose to base it on are:
1. Age
2. Sex
3. Smoker
Now, for each factor, I must define options, like so:
1. Age
a. 21-34
b. 35-64
c. 65-99
2. Sex
a. Male
b. Female
3. Smoker
a. Non-Smoker
b. Less than 1 pack per day
c. More than 1 pack per day
OK, now comes the hard part. I need to generate every possible permutation of these three factors individual options, like so:
1. Male, 21-34, Non-Smoker
2. Male, 35-64, Non-Smoker
3. Male, 65-99, Non-Smoker
4. Male, 21-34, Less than 1 pack per day
5. Male, 35-64, Less than 1 pack per day
6. Male, 65-99, Less than 1 pack per day
7. Male, 21-34, More than 1 pack per day
8. Male, 35-64, More than 1 pack per day
9. Male, 65-99, More than 1 pack per day
10. Female, 21-34, Non-Smoker
11. Female, 35-64, Non-Smoker
12. Female, 65-99, Non-Smoker
13. Female, 21-34, Less than 1 pack per day
14. Female, 35-64, Less than 1 pack per day
15. Female, 65-99, Less than 1 pack per day
16. Female, 21-34, More than 1 pack per day
17. Female, 35-64, More than 1 pack per day
18. Female, 65-99, More than 1 pack per day
Now, each of these factors can have any number of options (except for Sex, which can only be male or female.)
I have wasted 2 days on this problem. If anybody can help me, you'd be saving the rest of my hair. Thanks.