@Agyat: The code builds up the number one bit at a time. It finds the
smallest i such that the binomial coefficient i-choose-k is not less
than n. This says that there are at least n combinations of i bits
taken k at a time. In other words, the number must be an i-bit number.
Thus, since bits are numbered from 0, set bit i-1. Now decrease n by
(i-1)-choose-k and decrease k by 1 and iterate until all k bits are
assigned or until only 1-bits remain.

What is messy about it? Can you solve the problem as fast less
messily?

Dave

On Jul 13, 8:05 am, Agyat <[email protected]> wrote:
> @dev: good buudy.....it is working correctly........but can u explain
> it what it is doing.......it is really messy.........:(
>
> On Jul 10, 4:42 pm, Dave <[email protected]> wrote:
>
>
>
> > @Anurag: 
> > Seehttp://groups.google.com/group/algogeeks/msg/d90353c759125384?hl=en.
>
> > Dave
>
> > On Jul 10, 1:14 am, anurag <[email protected]> wrote:
>
> > > You are given two integers n and k
> > > k signifies number of set bits i.e. if k = 3 then output should have 3
> > > set bits.
> > > Output should be the nth smallest number having k set bits
> > > for example
> > > k=1 and n=3
> > > output should be
> > > 4 (00000100)- Hide quoted text -
>
> - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" 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/algogeeks?hl=en.

Reply via email to