Created
July 17, 2022 02:31
-
-
Save FerPerales/12915905b91629ce1536465d7d0cc650 to your computer and use it in GitHub Desktop.
fib.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# Calcula el n-ésimo número de la sucesión de Fibonacci | |
# Para correr desde la terminarl: | |
# ruby fib.rb argumento | |
# Donde argumento es el número de la sucesión a calcular | |
# Si el programa corre sin argumentos, calculará el número un millóon de la sucesión | |
# ruby fib.rb | |
number = ARGV[0]&.to_i || 1_000_000 | |
puts "Calculando el numero #{number} de la sucessión de Fibonacci" | |
values = [0, 1] | |
(2..number).each do |i| | |
values[i] = values[i - 1] + values[i - 2] | |
end | |
puts "El valor #{number} de la sucesión de Fibonacci es #{values[number]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment