Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # encoding: utf-8
- #
- # Licensed under GPLv2
- # Author: Hüseyin TEKINASLAN <huseyintekinaslan@gmail.com>
- #
- # This program is free software; you can redistribute it and/or modify it under
- # the terms of the GNU General Public License as published by the Free
- # Software Foundation; either version 2 of the License, or (at your option)
- # any later version.
- #
- class Hclass
- def initialize(number, base)
- @number = number
- @base = base
- end
- def base
- array0 = Array.new
- if @number.is_a?(Fixnum) and @base.is_a?(Fixnum)
- if @base != 0 and @base != 1 and @base > 1 and @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
- else
- return """Olası hata durumlarınız:
- * Taban 0 veya 1 olabilir.
- * Girdiğiniz sayı negatif olabilir.
- Girdilerinizi kontrol ediniz."""
- end
- else
- return "Sayı veya taban tamsayı olmalıdır."
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement