Skip to content

Instantly share code, notes, and snippets.

@stormwatch
Created May 20, 2020 10:28
Show Gist options
  • Save stormwatch/dd19a752c35df17b600d1f8871bf53f6 to your computer and use it in GitHub Desktop.
Save stormwatch/dd19a752c35df17b600d1f8871bf53f6 to your computer and use it in GitHub Desktop.
-module(perfect).
-export([perfect/1]).
perfect(N) ->
perfect(N, 2, 1).
perfect(N, D, Sum) when D * 2 < N, Sum < N ->
if
N rem D =:= 0 ->
perfect(N, D + 1, Sum + D + N div D);
true ->
perfect(N, D + 1, Sum)
end;
perfect(N, _D, Sum) ->
N =:= Sum.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment