Skip to content

Instantly share code, notes, and snippets.

@pppillai
Created May 9, 2020 20:39
Show Gist options
  • Save pppillai/441c92a96598046aea4638b05bbc19d2 to your computer and use it in GitHub Desktop.
Save pppillai/441c92a96598046aea4638b05bbc19d2 to your computer and use it in GitHub Desktop.
-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