Re: One-Liners Mashup (#177 again)



Matthew Moss <matthew.moss@xxxxxxxxx> wrote:

New challange:

Starting with an array, find the first permutation of the elements of
that array that is lexicographically greater than (i.e. sorts after)
the given array.

I was tempted to port the C++ next_permutation code, but then I
realized I have class. :(

I've done it, and posted it here, but It's not one line. I'm not sure
if that's even doable.

What I do know is that most permutation generators in Ruby just look
at positions, not data, and by doing so, they yield identical
permutations in a single iteration when there are indentical data
elements.

--Ken

--
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/
.



Relevant Pages

  • Re: Reversible sort algorithm
    ... The sorted array plus the sort-information will be ... of an available cell, ... You can get even more compression by packing the positions into a single ... most on bignums to decode the permutation index into the ...
    (comp.programming)
  • Re: Permutations - 8 columns
    ... > permutation I require but could not find one. ... > We have a database where all the financial information is stored. ... I would do this using a procedure that filled an array, ... the results to your target worksheet. ...
    (microsoft.public.excel.programming)
  • Re: Ranking Without Sorting
    ... > sorting the elements of the array. ... inverting and applying such a permutation can be done in linear time. ... You can avoid having to sort the input array by treating the output ...
    (comp.programming)
  • Re: Ranking Without Sorting
    ... >> sorting the elements of the array. ... > inverting and applying such a permutation can be done in linear time. ... > You can avoid having to sort the input array by treating the output ...
    (comp.programming)