Here's my non-cheating solution. Base-64 ftw!


def symbolify(n)
  unless $cache
    $cache = {}
    $cache[8] = "(?--?*--?--?()"
    $cache[64] = "(??--?)-?()"
  end

  if $cache.has_key?(n)
    $cache[n]
  else
    if n < 0
      "-(#{symbolify(-n)})"
    elsif n < 8
      case n
      when 0 then "??-??"
      when 1 then "?)-?("
      when 2 then "?*-?("
      when 3 then "?--?*"
      when 4 then "?--?)"
      when 5 then "?--?("
      when 6 then "?--?(--?)-?("
      when 7 then "?--?)--?--?*"
      end
    elsif n < 64
      q, r = n.divmod(8)
      if q.zero?
        symbolify(rs)
      else
        qs = symbolify(q)
        if r.zero?
          "(#{qs})*#{$cache[8]}"
        else
          rs = symbolify(r)
          "(#{qs})*#{$cache[8]}--#{rs}"
        end
      end
    else
      q, r = n.divmod(64)
      if q.zero?
        symbolify(rs)
      else
        qs = symbolify(q)
        if r.zero?
          "(#{qs})*#{$cache[64]}"
        else
          rs = symbolify(r)
          "#{rs}--(#{qs})*#{$cache[64]}"
        end
      end
    end
  end

end