Last active
August 29, 2015 14:15
-
-
Save huseyin/1a9b88b098f3ed8204dc to your computer and use it in GitHub Desktop.
Tam sayılar sınıfında taban değiştirme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: UTF-8 | |
# | |
# From -> Hüseyin Tekinaslan <[email protected]> | |
# | |
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