i need help with complicated question.
i need to find and print all the options to create subgroups from the numbers
: 1,2,3,4,5,6,7,8,9,10
in each option i need to use with all the numbers.
for example with just the numbers 1,2,3,4
the output will be:
two groups
option 1: (1) (2,3,4)
option 2: (2) (1,3,4)
option 3: (3) (2,1,4)
option 4: (4) (2,3,1)
option 5: (1,2)(3,4)
option 6: (1,3)(2,4)
option 7: (1,4)(2,3)
three groups
option 8: (1)(2)(3,4)
option 9: (1,2)(3)(4)
option 10: (1,3)(2)(4)
.........
.......
four group
(1)(2)(3)(4)
one group
(1,2,3,4)
sorry on my english
thanks alot !!

12-08-2010, 08:29 PM

JosAH

Quote:

Originally Posted by asafavi

i need help with complicated question.
i need to find and print all the options to create subgroups from the numbers
: 1,2,3,4,5,6,7,8,9,10
in each option i need to use with all the numbers.

That's the set partitioning problem; for a set of one element there's only one partition { a }; for a set of two elements there are two partitions { ab, { a b } }. The general recursive rulie is: given all partitions for a set of n-1 elements construct the partitions for a set of n elements as follows: add the new element to every set and create new partitions by taking the old partitions and adding a new one element partition containing the new element. The following code does just that:

thank u great!
i just want to know how i can convert the output from " Iterator" (i.next()) to array(int[]) or string.
i mean after the function will finish i want each option in each separate array (for each option)
thank u!!!!

12-09-2010, 12:05 PM

JosAH

Quote:

Originally Posted by asafavi

thank u great!
i just want to know how i can convert the output from " Iterator" (i.next()) to array(int[]) or string.
i mean after the function will finish i want each option in each separate array (for each option)
thank u!!!!

You're welcome; my method simply returns a List containing all partitions of a set (given in String form) because that was the essential part of your question. My test program just prints the entire list. It's up to you what you want to do with the List. I'm not going to split the List for you; you have to show some effort first.