Skip to content

Instantly share code, notes, and snippets.

@luketlancaster
Created November 3, 2015 18:49
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save luketlancaster/a82a1e41833e9503f161 to your computer and use it in GitHub Desktop.
Fibonacci method
index = ARGV[0].to_i
def fibb(times)
start = [0]
times.times do |x|
if x.zero?
start << 1
else
start << start[x -1] + start[x]
end
end
print start[times -1]
end
fibb(index)
@luketlancaster
Copy link
Author

James Logan solution, in JS

function fib (index){
  var seq = [0,1];
  while(seq.length < index+1) {
    seq[seq.length] = (seq[seq.length-1]) + (seq[seq.length -2]);
  }
  return seq[index]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment