Sha256: 45571c9595d11d1411236b51d464c37718d5280fec177167eec3424b429221d1

Contents?: true

Size: 890 Bytes

Versions: 1

Compression:

Stored size: 890 Bytes

Contents

require "sungemm/version"

module Sungemm
  # Finds the n-th fibonachi number.
  # @param n [Fixnum] element number in the fibonachi sequence.
  # @return [Fixnum] N-th fibo number.
  def self.fibo_finder(n)
    if (0..1).include?(n)
      n
    else
      fibo_finder(n-2)+fibo_finder(n-1)
    end
  end

  class Stack
    def initialize(array)
      @array = array
    end

    def pop(count = 1)
      r=@array.pop(count).reverse
      r=r.last if count==1
      r
    end

    def push(values)
      values.each {|x| @array << x}
      true
    end

    def to_a
      @array
    end
  end

  class Queue
    def initialize(array)
      @array = array
    end

    def pop(count = 1)
      r = @array.shift(count)
      r = r.first if count == 1
      r
    end

    def push(values)
      values.each { |x| @array << x }
      true
    end

    def to_a
      @array
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sungemm-0.0.2 lib/sungemm.rb