From: Adam Shelly Date: 2008-02-15T02:45:18+09:00 Subject: Re: my noob "numbering lines" programe. How to improve? On 2/14/08, Thomas Preymesser wrote: > On 13/02/2008, Adam Akhtar wrote: > > > > > > numdigits = 1 > > x = 1 > > while (x < totalnumlines) > > x = x * 10 > > numdigits = numdigits + 1 > > end > > > you don't need such a loop. this can be replaced with > > numdigits = Math.log10(totalnumlines).to_i+1 > Hint: why do math to calculate how many digits it takes to represent a number as a string, when you can just let the String class tell you?