Skip to content

Instantly share code, notes, and snippets.

@sangyongjung sangyongjung/Fibo.rb

Last active Aug 29, 2015
Embed
What would you like to do?
class Fibo
# attr_accessor :array
def initialize
@array = []
end
def get_array(limit)
limit
i = 0
loop do
if i == 0
@array << 1
elsif i == 1
@array << 2
else
new_value = @array[i-2].to_i + @array[i-1].to_i
break if new_value > limit
@array << new_value
end
i += 1
end
puts @array.to_s
end
def get_even_sum
@array.select{|e| e.even?}.reduce(:+)
end
end
fibo = Fibo.new
fibo.get_array(400000)
puts fibo.get_even_sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.