From: Li Chen Date: 2009-02-12T01:34:30+09:00 Subject: Re: how to do the recursion Matthew Williams wrote: >> The main idea behind recursion is that we break a problem into a > representation of the same problem. In this case, we are taking a > number, n. We want the value of that n, modulo 2, + the binary value of > (n / 2). > > Using that approach, for 4, we'd get: > > (n%2) + ((n/2)%2) + ((n/2)/2)%2 > > which is "001" -- the reverse of what we were wanting. However, if we > turn it around, we can say that the binary representation of n is > equivalent to: > > the binary representation of (n/2) + (n modulo 2) Hi Matt, Thank you very much. Your explanation is so sweet! Li -- Posted via http://www.ruby-forum.com/.