Skip to content

Instantly share code, notes, and snippets.

@passcod
Created February 9, 2013 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save passcod/4744766 to your computer and use it in GitHub Desktop.
Save passcod/4744766 to your computer and use it in GitHub Desktop.
Fastfib
function fastfib(n){
var i=0, fibs = [0,1];
for (; i < n; i += 1) {
fibs.push(fibs[0] + fibs[1]);
fibs.shift();
}
return fibs[0];
}
var n = 0, last = 0;
for (var n = 1; n < 1000000; n += 1) {
last += fastfib(200) / (n*n);
}
print(last);
# Python 2
def fastfib(n):
fibs = [0,1]
for i in xrange(0, n):
fibs.append(fibs[0] + fibs[1])
fibs.pop(0)
return fibs[0]
last = 0
for n in xrange(1, 1000000):
last += fastfib(200) / (n*n)
print last
def fastfib n
fibs = [0,1]
n.times {
fibs.push fibs[0] + fibs[1]
fibs.shift
}
fibs[0]
end
last = 0
1.step(1000000) { |n|
last += fastfib(200) / (n*n)
}
puts last
# Python 3
def fastfib(n):
fibs = [0,1]
for i in range(0, n):
fibs.append(fibs[0] + fibs[1])
fibs.pop(0)
return fibs[0]
last = 0
for n in range(1, 1000000):
last += fastfib(200) / (n*n)
print(last)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment