Created
May 9, 2020 20:39
-
-
Save pppillai/441c92a96598046aea4638b05bbc19d2 to your computer and use it in GitHub Desktop.
This file contains 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(week2_perfect_number). | |
-export([perfectNumber/1]). | |
-author("Pradeep Pillai"). | |
perfectNumber(N) -> | |
A = doPerfect(N, N div 2, []), | |
N == lists:sum(A). | |
doPerfect(_, 0, Result) -> | |
Result; | |
doPerfect(N, Num, Result) -> | |
if | |
N rem Num == 0 -> | |
doPerfect(N, Num - 1, lists:append(Result, [Num])); | |
true -> | |
doPerfect(N, Num - 1, Result) | |
end. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment