Re: Algorithm to generate permutation for a non sequential single array



mmarin1m@xxxxxxxxxxx wrote:
> I'm looking for an algorithm that would generate all permutations for a
> given non sequential list.

As others have already said, you are asking for the list of all subsets,
nothing to do with permutations.

The following 3-line OCaml function does this:

let rec subsets = function
[] -> [[]]
| h :: t -> (fun t -> List.map (fun t -> h :: t) t @ t) (subsets t);;

For example:

# let rec subsets = function
[] -> [[]]
| h :: t -> (fun t -> List.map (fun t -> h :: t) t @ t) (subsets t);;
val subsets : 'a list -> 'a list list = <fun>
# subsets [125; 126; 5; 88; 33];;
- : int list list =
[[125; 126; 5; 88; 33]; [125; 126; 5; 88]; [125; 126; 5; 33]; [125; 126; 5];
[125; 126; 88; 33]; [125; 126; 88]; [125; 126; 33]; [125; 126];
[125; 5; 88; 33]; [125; 5; 88]; [125; 5; 33]; [125; 5]; [125; 88; 33];
[125; 88]; [125; 33]; [125]; [126; 5; 88; 33]; [126; 5; 88]; [126; 5; 33];
[126; 5]; [126; 88; 33]; [126; 88]; [126; 33]; [126]; [5; 88; 33]; [5; 88];
[5; 33]; [5]; [88; 33]; [88]; [33]; []]

--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com
.



Relevant Pages

  • Re: Help with Permutations
    ... calculate the subset of permutations according to the rules above. ... same letters are part of the output required: ... run the algorithm. ... Prev by Date: ...
    (sci.math)
  • Re: Help with Permutations
    ... > calculate the subset of permutations according to the ... > run the algorithm. ... for 'acccdde' permutations shall be ... Prev by Date: ...
    (sci.math)
  • Re: Extending the length of a key
    ... permutations, a series of characters from a given set including ... adequate first step...knowing that your have a real crypto algorithm ... characters each, and another one that I liked better required 200 ... are bases more conducive to strong cryptography than binary. ...
    (sci.crypt)
  • Re: Extending the length of a key
    ... permutations, a series of characters from a given set including ... adequate first step...knowing that your have a real crypto algorithm ... are bases more conducive to strong cryptography than binary. ... Then could you please either explain this better technique or at least ...
    (sci.crypt)
  • Re: Strategy or Iterator?
    ... private int count; ... Dijkstra's algorithm generates permutations, ... All possible subsequences of length N of the input (considered to be ...
    (comp.lang.java.programmer)