I just found a few typos in my non-cheating version that were not
caught. I fixed them and shortened the solution a bit:


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

  def symbobase(b, n)
    q, r = n.divmod(b)
    if q.zero?
      symbolify(r)
    else
      qs = symbolify(q)
      if r.zero?
        "(#{qs})*#{$cache[b]}"
      else
        "#{symbolify(r)}--(#{qs})*#{$cache[b]}"
      end
    end
  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
      symbobase(8, n)
    else
      symbobase(64, n)
    end
  end

end