Skip to main content
2 of 8
More golfing
Sherlock9
  • 12.3k
  • 1
  • 30
  • 68

Ruby, 113 112 bytes

I sort of double-posted my Python answer (somehow), so here's a Ruby answer.

a=->n,f,t,d{z=0;s='';n.split(s).map{|i|z=(z+d.index(i))*f};z/=f;(z,m=z.divmod(t);s=d[m]+s)while z>0;s[0]?s:d[0]}

Ungolfed:

def a(n,f,t,d)
  z=0
  s=''
  n.split(s).each do |i|    # viable because s == '' at this stage
    z = (z + d.index(i)) * f
  end
  z/=f
  while z>0
    z,m = z.divmod(t)
    s = d[m] + s
  end
  if s[0]   # if n not zero
    return s
  else
    return d[0]
  end
end
Sherlock9
  • 12.3k
  • 1
  • 30
  • 68