I hereby claim:
- I am guillaumebihet on github.
- I am guillaume_b (https://keybase.io/guillaume_b) on keybase.
- I have a public key ASC7HhBT0oei5fpDZ8B-ru72SHhbtdOcbd3cP9MXslM_EQo
To claim this, I am signing this object:
class Star | |
attr_accessor :name, :spectral_class, :type | |
def initialize(name, spectral_class, type) | |
@name = name | |
@spectral_class = spectral_class | |
@type = type | |
end | |
def describe |
class Tree | |
attr_accessor :payload, :children | |
def initialize(payload, children) | |
@payload = payload | |
@children = children | |
end | |
end | |
#The "Leafs" of the tree, elements that have no children |
class Tree | |
attr_accessor :payload, :children | |
def initialize(payload, children) | |
@payload = payload | |
@children = children | |
end | |
def self.build_k_ary_tree(array, k) #where k = number of children per node | |
raise Exception, 'A node cannot have a negative number of children' if k < 0 |
def self.build_random_tree(array, k) | |
raise Exception, 'A node cannot have a negative number of children' if k < 0 | |
first = array.delete_at(rand(array.length)) #choose randomly an item and remove it | |
rest = array.shuffle! #shuffle the rest of the array | |
trunk = Tree.new(first, Array.new(rand(k+1), nil)) #trunk is created with an array | |
#made of a random number nil elements that is greater or equal to 0 and less than k+1 | |
#(i.e. less or equal to k). In other words, with a number of nodes between zero and k | |
rest.each do |i| | |
queue = [trunk] |
I hereby claim:
To claim this, I am signing this object: