Skip to main content
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

Ruby, 113 112 105 98 97 95 87 bytes

I sort of double-posted my Python answer (somehow), so here's a Ruby answer. Seven more bytes thanks to manatworkmanatwork, another byte thanks to Martin BüttnerMartin Büttner, and 8 more bytes thanks to cia_ranacia_rana.

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

Ungolfed:

def a(n,f,t,d)
  z=0
  s=''
  n.chars do |i|
    z = z*f + d.index(i)
  end
  while z>0 
    s = d[z%t] + s
    z /= t
  end
  if s[0]   # if n not zero
    return s
  else
    return d[0]
  end
end

Ruby, 113 112 105 98 97 95 87 bytes

I sort of double-posted my Python answer (somehow), so here's a Ruby answer. Seven more bytes thanks to manatwork, another byte thanks to Martin Büttner, and 8 more bytes thanks to cia_rana.

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

Ungolfed:

def a(n,f,t,d)
  z=0
  s=''
  n.chars do |i|
    z = z*f + d.index(i)
  end
  while z>0 
    s = d[z%t] + s
    z /= t
  end
  if s[0]   # if n not zero
    return s
  else
    return d[0]
  end
end

Ruby, 113 112 105 98 97 95 87 bytes

I sort of double-posted my Python answer (somehow), so here's a Ruby answer. Seven more bytes thanks to manatwork, another byte thanks to Martin Büttner, and 8 more bytes thanks to cia_rana.

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

Ungolfed:

def a(n,f,t,d)
  z=0
  s=''
  n.chars do |i|
    z = z*f + d.index(i)
  end
  while z>0 
    s = d[z%t] + s
    z /= t
  end
  if s[0]   # if n not zero
    return s
  else
    return d[0]
  end
end
More golfing
Source Link
Sherlock9
  • 12.3k
  • 1
  • 30
  • 68

Ruby, 113 112 105 98 97 9595 87 bytes

I sort of double-posted my Python answer (somehow), so here's a Ruby answer. Seven more bytes thanks to manatwork and, another byte thanks to Martin Büttner, and 8 more bytes thanks to cia_rana.

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

Ungolfed:

def a(n,f,t,d)
  z=0
  s=''
  n.chars do |i|
    z = z*f + d.index(i)
  end
  while z>0 
    z,ms = z.divmodd[z%t] t+ s
    sz /= d[m] + st
  end
  if s[0]   # if n not zero
    return s
  else
    return d[0]
  end
end

Ruby, 113 112 105 98 97 95 bytes

I sort of double-posted my Python answer (somehow), so here's a Ruby answer. Seven more bytes thanks to manatwork and another byte thanks to Martin Büttner.

->n,f,t,d{z=0;s='';n.chars{|i|z=z*f+d.index(i)};(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.chars do |i|
    z = z*f + d.index(i)
  end
  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

Ruby, 113 112 105 98 97 95 87 bytes

I sort of double-posted my Python answer (somehow), so here's a Ruby answer. Seven more bytes thanks to manatwork, another byte thanks to Martin Büttner, and 8 more bytes thanks to cia_rana.

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

Ungolfed:

def a(n,f,t,d)
  z=0
  s=''
  n.chars do |i|
    z = z*f + d.index(i)
  end
  while z>0 
    s = d[z%t] + s
    z /= t
  end
  if s[0]   # if n not zero
    return s
  else
    return d[0]
  end
end
More golfing
Source Link
Sherlock9
  • 12.3k
  • 1
  • 30
  • 68

Ruby, 113 112 105 98 9797 95 bytes

I sort of double-posted my Python answer (somehow), so here's a Ruby answer. Seven more bytes thanks to manatwork and another byte thanks to Martin Büttner.

a=->n,f,t,d{z=0;s='';n.chars{|i|z=z*f+d.index(i)};(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.chars do |i|
    z = z*f + d.index(i)
  end
  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

Ruby, 113 112 105 98 97 bytes

I sort of double-posted my Python answer (somehow), so here's a Ruby answer. Seven more bytes thanks to manatwork and another byte thanks to Martin Büttner.

a=->n,f,t,d{z=0;s='';n.chars{|i|z=z*f+d.index(i)};(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.chars do |i|
    z = z*f + d.index(i)
  end
  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

Ruby, 113 112 105 98 97 95 bytes

I sort of double-posted my Python answer (somehow), so here's a Ruby answer. Seven more bytes thanks to manatwork and another byte thanks to Martin Büttner.

->n,f,t,d{z=0;s='';n.chars{|i|z=z*f+d.index(i)};(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.chars do |i|
    z = z*f + d.index(i)
  end
  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
added 123 characters in body
Source Link
Sherlock9
  • 12.3k
  • 1
  • 30
  • 68
Loading
deleted 13 characters in body
Source Link
Sherlock9
  • 12.3k
  • 1
  • 30
  • 68
Loading
More golfing
Source Link
Sherlock9
  • 12.3k
  • 1
  • 30
  • 68
Loading
Post Undeleted by Sherlock9
More golfing
Source Link
Sherlock9
  • 12.3k
  • 1
  • 30
  • 68
Loading
Post Deleted by Sherlock9
Source Link
Sherlock9
  • 12.3k
  • 1
  • 30
  • 68
Loading