On Sun, Jul 13, 2008 at 6:08 PM, Matthew Moss <matthew.moss / gmail.com> wrote: > My first version cheats a bit, but passes the tests. Converts the num > to base-5 and back. > > def symbolify(num) > def eval(str) > str.tr('(?*)-', '01234').to_i(5) > end > num.to_s(5).tr('01234', '(?*)-') > end > > > My second solution cheats badly, failing the delayed eval test. Still, > it's a single line of length 42. :) > > def symbolify(num) > def eval(str) $num end; $num = num; "()" > end > > > I need to finish my non-cheating version... > > But this is brilliant Matt, why cheat, we can do this without cheating too ;) @digits = %w{ ??-?? ?)-?( ?*-?( ?--?* ?--?) ?--?( } def symbolify i s = i.to_s( 5 ).split( // ) f = s.shift s.inject( @digits[f.to_i] ){ |so_far, b| "(#{so_far})*(" << @digits[ 5 ] << ")--" << @digits[ b.to_i ] } end Cheers Robert