Last active
June 28, 2016 10:58
-
-
Save ngnguyen1/abbd4cd3626cfe8b0797bdb87efb3b89 to your computer and use it in GitHub Desktop.
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
%% This is linear recursion | |
plus(X,0) -> X; | |
plus(X,Y) -> 1 + plus(X,Y-1). | |
%% This is tail recursion | |
tail_plus(X,Y) -> tail_plus(X,Y,X). | |
tail_plus(_,0,Acc) -> Acc; | |
tail_plus(X,Y,Acc) -> | |
tail_plus(X,Y-1,1+Acc). | |
%% Modified by Mr.Thang =)) | |
tail_plus(X,0) -> X; | |
tail_plus(X,Y) -> | |
tail_plus(1+X,Y-1). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment