Hi, I have a simple problem for which I need nested loops with variable depth. As I don't know how to do that, so I have searched the net, and I do not understand the solutions they provide. Could someone eventually look at the following and help me ?
I wish to generate all the possible partitions of n objects into m different locations, with at least one object in every location. For instance, with 5 objects and 3 locations, one has 6 possibilities:
{1}{1}{3}, {1}{2}{2}, {1}{3}{1}, {2}{1}{2}, {2}{2}{1}, {3}{1}{1},
When m=4, the program would be:
do i1 = 1, n-m+1
do i2 = 1, n-i1-1
do i3 = 1, n-i1-i2-1
i4 = n-i1-i2-i3
write(*,*) i1, i2, i3, i4
enddo
enddo
enddo
But I would like to generalize this for any value of m that the user would ask for. How can I do that ?
Thank you for your help.
I wish to generate all the possible partitions of n objects into m different locations, with at least one object in every location. For instance, with 5 objects and 3 locations, one has 6 possibilities:
{1}{1}{3}, {1}{2}{2}, {1}{3}{1}, {2}{1}{2}, {2}{2}{1}, {3}{1}{1},
When m=4, the program would be:
do i1 = 1, n-m+1
do i2 = 1, n-i1-1
do i3 = 1, n-i1-i2-1
i4 = n-i1-i2-i3
write(*,*) i1, i2, i3, i4
enddo
enddo
enddo
But I would like to generalize this for any value of m that the user would ask for. How can I do that ?
Thank you for your help.