Skip to content

Instantly share code, notes, and snippets.

@apg
Created November 15, 2011 23:03
Show Gist options
  • Save apg/1368659 to your computer and use it in GitHub Desktop.
Save apg/1368659 to your computer and use it in GitHub Desktop.
-module(m).
-export([pow/2, digitsum/1]).
pow(B, N) when is_integer(N), N >= 0 -> pow(B, N, 1).
pow(_, 0, A) -> A;
pow(B, N, A) -> pow(B, N-1, A*B).
digitsum(N) when is_integer(N) -> lists:sum([X - $0 || X <- integer_to_list(N)]).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment