Last active
August 29, 2015 13:57
-
-
Save googya/9896080 to your computer and use it in GitHub Desktop.
fog jumps the ladder, 1,2,3
This file contains hidden or 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
-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