On Sun, 11 Feb 2007 06:30:52 -0800, Phrogz wrote:

> Here are my solutions to Quiz #113. For some of them I just couldn't
> help but to provide a couple variations.
> 
> Because I'm a terrible golfer, most strive for elegance (in some form)
> over terseness.
> 
> 
> # 1 - Commafy Numerics
> i,f=quiz.to_s.split('.'); i.gsub(/(\d)(?=\d{3}+$)/,'\\1,') + (f ?
> ('.'+f) : '')

Good answer. you helped me golf mine down a little bit by getting rid of
array indexing:

i,f=i.to_s.split('.');"#{i.reverse.scan(/.{1,3}/).join(',').reverse}.#{f}"

> 
> # 3 - Shuffle Array
> quiz.sort_by{ rand }

I feel stupid for taking such a longer answer. And I've used sort_by{rand}
too to do this, if not in Ruby then in SQL, so I feel stupid for not
thinking of it in this context.]

mine, as I posted elsewhere was:
i.inject([]){|cur,val| cur.insert(rand(cur.length+1),val)}


> #5 - Paragraph Wrapping - extra work to not put a new line on the last
> line
> quiz.gsub( /^(.{1,40})($|[ \t]+)/ ){ $2.empty? ? $1 : "#{$1}\n" }

I like this one a lot. My only answer was way too long, and far more
complicated.



-- 
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/