From: Phrogz Date: 2007-02-11T23:35:09+09:00 Subject: [SOLUTION] One-Liners (#113) 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) : '') # 2 - Flatten_Once a=[]; quiz.each{ |x| Array===x ? a.concat(x) : a<1; a << ( n%2==0 ? n/=2 : n=(n*3)+1 ); end; a #10 - Array to Nested Hash, direct indexing... a=quiz; h={a[-2]=>a[-1]}; (a.size-3).downto(0){ |i| h={a[i]=>h} }; h #...or a slightly different way... a=quiz; y,z=a[-2..-1]; h={y=>z}; a[0..-3].reverse.each{ |o| h={o=>h} }; h #...or poppin' values for a tighter format... a=quiz; z,y=a.pop,a.pop; h={y=>z}; a.reverse.each{ |o| h={o=>h} }; h #...and one last, just because I love Hash.[] a=quiz.reverse; h=Hash[a.shift,a.shift].invert; a.each{ |o| h={o=>h} }; h