Skip to content

Instantly share code, notes, and snippets.

@googya
Last active August 29, 2015 13:57
Show Gist options
  • Save googya/9896080 to your computer and use it in GitHub Desktop.
Save googya/9896080 to your computer and use it in GitHub Desktop.
fog jumps the ladder, 1,2,3
-module(n_fibonacci).
-export([f/1]).
f(N) ->
fib(0,0,1,N).
fib(_, _, S, 0) -> S;
fib(S1, S2, S3, T) ->
fib(S2, S3, S1 + S2 + S3 ,T-1).
%% 青蛙跳阶梯的例子, 实际就是3阶的斐波那契数列。 采用尾递归的方式, 效率更高, 不会爆栈
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment