From: Alex Young Date: 2007-02-12T08:40:18+09:00 Subject: Re: [QUIZ] One-Liners (#113) My solutions. Be gentle, this is my first quiz :-) I haven't checked these against any of the test cases that were posted, but I think a couple of them are interesting. # Commify numbers. def one(quiz) quiz.to_s.reverse.gsub(/(\d{3})(?=\d)/,'\1,').reverse end # Commify numbers again, but ignore any before the decimal point. def one_alternate(quiz) a,b=quiz.to_s.split('.');[a.reverse.gsub(/(\d{3})(?=\d)/,'\1,').reverse,b].join('.') end # One-level flatten(). def two(quiz) r=[];quiz.each{|a|r+=[*a]};r end # Array shuffling the noddy way. def three(quiz) r={};quiz.each{|a|r[a]=nil};r.keys end # Array shuffling the proper way. def three_alternate(quiz) r=[];quiz.size.times{r< m}} end -- Alex