On Jul 13, 2008, at 09:08 , Matthew Moss 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

This was my cheating solution as well, written slightly differently:

FROM, TO = '01234', '?*()-'

def symbolify n
   n.to_s(5).tr(FROM, TO)
end

alias :real_eval :eval
def eval s
   return real_eval(s) unless s =~ /^[#{Regexp.escape TO}]+$/
   s.tr(TO, FROM).to_i(5)
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

that however, is _horrible_. :P