Last active
May 17, 2020 02:52
-
-
Save sushant12/0c3d4a50816b0880b901c8ea1c46bd4c 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(assignment4). | |
-export([fib/1, perfect/1]). | |
fib(N) -> fib_tail(N, 0, 1). | |
fib_tail(0, X,_Y) -> X; | |
fib_tail(N, X, Y) when N > 0 -> fib_tail(N - 1, X + Y, X). | |
perfect(N) when N > 0 -> sum_divisors(N div 2, N, 0). | |
sum_divisors(0, A, C) -> A == C; | |
sum_divisors(N, A, C) when A rem N == 0 -> sum_divisors(N - 1, A, C + N); | |
sum_divisors(N, A, C) when A rem N =/= 0 -> sum_divisors(N -1, A, C). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment