From: Stu Date: 2011-04-22T17:43:07+09:00 Subject: Re: Reversing a string without using array, classes and reverse function One more with ruby blocks (This would be the ruby way =) ) s = "1234567890" r = String.new s.length.times{|i| r << s[(i+1)*(-1)]} r == s.reverse true cheers!!! That was fun!!!... give me another =) ~Stu On Fri, Apr 22, 2011 at 3:32 AM, Stu wrote: > On Fri, Apr 22, 2011 at 2:45 AM, Jose Calderon-Celis > wrote: > >> for j in 1..len do >>  mycommand += s[-1*j] >> >> > > very nice I like the use of your math. By multiplying the array index > by negative one your sending the index a reverse number while your for > loop traverses forward. This is perfect logic. > > Here is a rewrite with my while loop: > > s = "1234567890" > r=String.new > i = 1 > while i <= s.length >  r << s[i*(-1)] >  i+=1 > end > printf s > "0987654321" >  => "0987654321" >> y == x.reverse > true >