Robert Klemme
2/14/2008 9:35:00 AM
2008/2/14, Phrogz <phrogz@mac.com>:
> On Feb 13, 3:50 pm, Adam Akhtar <adamtempor...@gmail.com> wrote:
> > Give us hints on how to improve this program. If you want to show your
> > code off then go ahead but please give us the hints first i.e. what
> > methods you would use, what you would rewrite in my code etc. Its so
> > much better for me to go away and try and replicate your thinking than
> > just reading it.
>
>
> Here are some suggestions:
> * Use the += and *= compound assignment operators
> * Use << instead of .write
> * "%10s" % str is like rjust, so
> * "%#{numdigits}s %s" % [ linenumber, input ]
Or rather
"%*d %s" % [numdigits, linenumber, input ]
printf "%*d %s", numdigits, linenumber, input
> * Look at each_with_index
> * Think about a better way to calculate numdigits; e.g.:
> * Math.log10( max ).ceil
> * total_lines.to_s.size
* Look at ARGF and ARFG.lineno
Kind regards
robert
--
use.inject do |as, often| as.you_can - without end