Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
=begin
def triple_sequence(start, length)
result = [start]
n = 0
while n < length - 1
result << result [n] * 3
n += 1
end
return result
end
=end
def fibonacci(length)
n = 0
result = [1, 1]
if length == 0
return []
elsif length == 1
return [1]
end
while result.length < length
last = result[-1]
sec_last = result[-2]
result << last + sec_last
end
result.shift
return result
end
print triple_sequence(2, 4) # => [2, 6, 18, 54]
puts
print triple_sequence(4, 5) # => [4, 12, 36, 108, 324]
puts
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more