[SLUG] Re: [PIG] Enumerate possible permutations?

From: Levi Bard (taktaktaktaktaktaktaktaktaktak@gmail.com)
Date: Fri Jul 14 2006 - 13:09:25 EDT


BTW, here was my solution, in Java:

        private static ArrayList<ArrayList<Integer> >
permuteList(ArrayList<Integer> list){
                ArrayList<Integer> tmp = null;
                ArrayList<ArrayList<Integer> > retlists = null;
                ArrayList<ArrayList<Integer> > alllists = new
ArrayList<ArrayList<Integer> >();
                
                if(null == list || 1>list.size()){
                        return null;
                }//if bad list
                
                for(Integer item: list){
                        if(null == item){ continue; } //type check
                        
                        tmp=new ArrayList<Integer>(list);
                        tmp.remove(item);
                        
                        retlists=permuteList(tmp);
                        if(null == retlists){
                                alllists = new ArrayList<ArrayList<Integer> >();
                                alllists.add(list);
                                return alllists;
                        }//no lists returned
                        
                        for(ArrayList<Integer> permutation: retlists){
                                permutation.add(item);
                                alllists.add(permutation);
                        }//for each returned sub-permutation
                }//for each item in list
                
                return alllists;
        }//permuteList

-- 
Tcsh: Now with higher FPS!
http://www.gnu.org/philosophy/shouldbefree.html
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS).  Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 20:42:22 EDT