Class: Integer

Inherits:
Object
  • Object
show all
Defined in:
lib/pebbles/nyarucode.rb

Overview

n進法

Instance Method Summary collapse

Instance Method Details

#base_of(b) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pebbles/nyarucode.rb', line 23

def base_of(b)
  if self < 0
    return((-self).base_of(b).map{ |x| -x })
  elsif self == 0
    return [0]
  end
  
  result = []
  x = self
  while x > 0
    result << (x % b)
    x /= b
  end
  
  result
end