yeah its josephus_problem.
I remember reading it somewhere that the following algorithm is a slick
solution..

Take the bit representation of the number  (n)
Left Rotate it by 1 bit.
The resulting number is your solution...

Wait ill check it.. Ya it works. I think it can be proved with some math .
And this solution is correct only if k is 2 (ie every alternate fellow left
is eliminated) ...
There should be a similar mathematically provable solution in for any k as
well. Let someone good at math prove that here...

On 2/22/07, Jair Cazarin <[EMAIL PROTECTED]> wrote:
>
> A classic problem: http://en.wikipedia.org/wiki/*Josephus*_*problem*
>
> On 2/22/07, Ravi Shankar <[EMAIL PROTECTED]> wrote:
> >
> >
> > Manish Garg wrote:
> > >
> > > so N and k is given to us and we have to tell that who will be the
> > > last person.
> > >
> > >
> > IIRC there is something on this in ``Concrete Mathematics'' by Knuth
> >
> >
> > http://slipvayne.googlepages.com
> > > >
> >


-- 
regards,
Amit

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to