permutation function problem



Hi All
I am trying to create a permutation function. I found the
implementation online, but the implementation uses for() loop in the
main() and it has the List as a parameter. All I am trying to do is to
modify the implementation, so that all the loops are in the function
and the parameter is a char array instead of a list.

The online implementations prints all the entry:
i.e
1.
0: ABC
2.
1: ACB
3.
2: BAC
4.
3: BCA
5.
4: CAB
6.
5: CBA

However, my function can only print ABC. I can't figure out where I
did wrong.

Could someone please help.. I would really appreciate it

Here is the online implementation:

public static <T> List<T> permute(List<T> list, int r) {
int n= list.size();
int f= fac(n);
: List<T> perm= new ArrayList<T>();

list= new ArrayList<T>(list);
for (list= new ArrayList<T>(list); n > 0; n--, r%= f) {

f/= n;
perm.add(list.remove(r/f));
}

return perm;

}


public static void main(String[] args) {
List<String> list= Arrays.asList("A", "B", "C");
for (int i= 0, n= 3, f= fac(n); i < f; i++)
System.out.println(i+": "+perm(list, i));
}
}


Here is my implementation(not working)

public static List permute(char [] input) {

List list = new ArrayList();
for(int count=0; count<input.length; count++){
list.add(input[count]);
}

list = new ArrayList(list);

List perm= new ArrayList();

for(int r=0, n=3, f=6; r<f; r++){
for (list= new ArrayList(list); n > 0; n--, r%=f) {

f/= n;

perm.add(list.remove(r/f));

}
System.out.print("r = " + r);
System.out.println(perm);
}

System.out.print("permSize = " + perm.size());

return perm;

}

public static void main(String[] args) {
char array[] = {'a', 'b', 'c'};
List list = new ArrayList();
list = permute(array);
System.exit(0);
}

.



Relevant Pages

  • Re: Generic Script Resource error
    ... > I have been trying to use a generic script resource to control MS Virtual ... The Error ID when I try to bring the resource online is 5018 ... > Set oExec = objVM.Startup ...
    (microsoft.public.windows.server.clustering)
  • Re: Can I apply PERM through both Mail & Online?
    ... You will not need to formally cancel the second application. ... and want to apply for the PERM. ... I think the online application will be approved much faster than ...
    (misc.immigration.usa)
  • Can I apply PERM through both Mail & Online?
    ... and want to apply for the PERM. ... For some special reasons, I want to apply for the PERM through both of ... I think the online application will be approved much faster than the ... do I need to cancel the mail application? ...
    (misc.immigration.usa)
  • Re: disk space used in AIX 5.1L
    ... This script will loop through your online volume groups to find the ...
    (comp.unix.aix)
  • Re: Can I apply PERM through both Mail & Online?
    ... You are free to waste as much money in application fees as you desire. ... You will not need to formally cancel the second application. ... and want to apply for the PERM. ... I think the online application will be approved much faster than the ...
    (misc.immigration.usa)