Created
June 15, 2015 22:52
-
-
Save ajbeach2/2260198a832f891ad306 to your computer and use it in GitHub Desktop.
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
def fib_mod(a,b,x,sequence = []) | |
if x == 1 | |
result = a | |
elsif x == 2 | |
result = b | |
else | |
result1 = sequence[x - 1] ||= fib_mod(a,b,x - 1, sequence) | |
result2 = sequence[x - 2] ||= fib_mod(a,b,x - 2, sequence) | |
result = result1**2 + result2 | |
end | |
sequence[x] = result | |
return result | |
end | |
args = gets | |
puts fib_mod(*args.split(' ').map{|x| x.to_i}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment