http://en.wikipedia.org/wiki/Permutation

2009/9/13 Faiz Bashir <[email protected]>

> Could u provide the Wikipedia link?
>
>
> On Sun, Sep 13, 2009 at 7:09 AM, Grant Kot <[email protected]> wrote:
>
>> there's a language that has that? anyway, wikipedia has sums everything up
>> nicely in four easy steps:
>>>
>>> The following algorithm generates the next permutation lexicographically
>>> after a given permutation. It changes the given permutation in-place.
>>>
>>>    1. Find the highest index *i* such that s[i] < s[i+1]. If no such
>>>    index exists, the permutation is the last permutation.
>>>    2. Find the highest index *j* > *i* such that s[j] > s[i]. Such a *j* 
>>> must
>>>    exist, since *i*+1 is such an index.
>>>    3. Swap s[i] with s[j].
>>>    4. Reverse all the order of all of the elements after index *i*
>>>
>>> if the current number is already the last lexicographic permutation and
>> there is no next one, then i basically just have an integer array of length
>> 10 and find the number of occurrences for 0-9. then i find the smallest
>> digit greater than 0 that occurs, and make it the first character in a
>> string, then i add a 0 and then i do a for loop through the occurrences
>> array and add that many of each number to the string.
>>
>>
>>
>
> >
>


-- 
Kind Regards,

Ahmed Medhat
Computer Science
Alexandria university
Egypt

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-codejam" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-code?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to