Created
June 27, 2017 09:40
-
-
Save marcincembrzynski/dcec0c91fa8d5481342b6e26cd6f4834 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
-module(rec). | |
-export([fib2/1,fib2Acc/3,perfectAcc/3,perfect/1]). | |
fib2(0) -> 0; | |
fib2(N) -> fib2Acc(0,1,N - 1). | |
fib2Acc(_,B,0) -> B; | |
fib2Acc(A,B,N) -> fib2Acc(B, A+B , N - 1). | |
perfect(N) -> N == (perfectAcc(N,N-1,0)). | |
perfectAcc(_,0,ACC) -> ACC; | |
perfectAcc(N,D,ACC) -> | |
if (N rem D) =:= 0 -> perfectAcc(N,D - 1,ACC + D) | |
; true -> perfectAcc(N,D - 1,ACC) | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment