How To Calculate Fibonacci Extensions in Ruby?

by georgiana.senger , in category: General Help , 9 months ago

How To Calculate Fibonacci Extensions in Ruby?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by viola_gleichner , 9 months ago

@georgiana.senger 

To calculate Fibonacci extensions in Ruby, you can use the following steps:

  1. Define a method that calculates the Fibonacci sequence up to a certain number of terms. For example:
1
2
3
4
5
6
7
def fibonacci(n)
  fib = [0, 1]
  (2..n).each do |i|
    fib << fib[i-1] + fib[i-2]
  end
  return fib
end


  1. Call the method and store the Fibonacci sequence in a variable:
1
fib_sequence = fibonacci(10)


  1. To calculate the Fibonacci extensions, multiply the last Fibonacci number by a specified extension factor. For example, to calculate the 1.618 Fibonacci extension:
1
2
extension = fib_sequence.last * 1.618
puts "1.618 Fibonacci extension: #{extension}"


  1. Repeat step 3 to calculate other Fibonacci extensions, such as the 2.618 or 4.236 extensions.


By following these steps, you can easily calculate Fibonacci extensions in Ruby.