Skip to content

Instantly share code, notes, and snippets.

@huseyin
Last active August 29, 2015 14:15
Show Gist options
  • Save huseyin/1a9b88b098f3ed8204dc to your computer and use it in GitHub Desktop.
Save huseyin/1a9b88b098f3ed8204dc to your computer and use it in GitHub Desktop.
Tam sayılar sınıfında taban değiştirme
# encoding: UTF-8
#
# From -> Hüseyin Tekinaslan <huseyin.tekinaslan@bil.omu.edu.tr>
#
class HClass
def initialize(number, base)
@number = number
@base = base
end
def base
array0 = Array.new
if @number.is_a?(Fixnum) && @base.is_a?(Fixnum)
if @base != 0 && @base != 1 && @base > 1 && @number >= 0
instance = @number
while true
remaining = instance - ((instance / @base) * @base)
instance = instance / @base
if instance > 1
array0 << remaining
else
array0 << remaining << instance
break
end
end
if array0[-1] == 0 then array0.pop(1) end
return array0.reverse.join.to_i
else
exit(stdout=true)
end
else
exit(stdout=true)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment