Merge pull request #150 from msaf9/master

This commit is contained in:
Vitor Oliveira 2021-05-24 23:09:03 -07:00 committed by GitHub
commit 3f8a50a2e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 0 deletions

View file

@ -98,6 +98,7 @@
* [Fibonacci](https://github.com/TheAlgorithms/Ruby/blob/master/maths/fibonacci.rb) * [Fibonacci](https://github.com/TheAlgorithms/Ruby/blob/master/maths/fibonacci.rb)
* [Find Max](https://github.com/TheAlgorithms/Ruby/blob/master/maths/find_max.rb) * [Find Max](https://github.com/TheAlgorithms/Ruby/blob/master/maths/find_max.rb)
* [Find Min](https://github.com/TheAlgorithms/Ruby/blob/master/maths/find_min.rb) * [Find Min](https://github.com/TheAlgorithms/Ruby/blob/master/maths/find_min.rb)
* [Lucas Series](https://github.com/TheAlgorithms/Ruby/blob/master/maths/lucas_series.rb)
* [Number Of Digits](https://github.com/TheAlgorithms/Ruby/blob/master/maths/number_of_digits.rb) * [Number Of Digits](https://github.com/TheAlgorithms/Ruby/blob/master/maths/number_of_digits.rb)
* [Power Of Two](https://github.com/TheAlgorithms/Ruby/blob/master/maths/power_of_two.rb) * [Power Of Two](https://github.com/TheAlgorithms/Ruby/blob/master/maths/power_of_two.rb)
* [Prime Number](https://github.com/TheAlgorithms/Ruby/blob/master/maths/prime_number.rb) * [Prime Number](https://github.com/TheAlgorithms/Ruby/blob/master/maths/prime_number.rb)

31
maths/lucas_series.rb Normal file
View file

@ -0,0 +1,31 @@
# A ruby program for Lucas series
#
# The Lucas numbers, commonly denoted L(n) form a sequence,
# called the Lucas series, such that each number is the sum
# of the two preceding ones, starting from 2 and 1. That is,
#
# L(0) = 2, L(1) = 1
# L(n) = L(n - 1) + L(n - 2), for n > 1.
#
# Given n, calculate L(n).
# Example: 2 1 3 4 7 11 18...
# Resource: https://en.wikipedia.org/wiki/Lucas_number
def lucas(number)
golden_ratio = (1 + 5**0.5) / 2
((golden_ratio**number).round()).to_i
rescue
"Error: Provide number only!"
end
puts lucas(4)
# 7
puts lucas(3)
# 4
puts lucas("3")
# Error: Provide number only!
puts lucas(2)
# 3