Skip to content

Instantly share code, notes, and snippets.

@apg
Created November 15, 2011 22:38
Show Gist options
  • Save apg/1368606 to your computer and use it in GitHub Desktop.
Save apg/1368606 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:foldl(fun (C, Acc) -> (C - $0) + Acc end,
0, integer_to_list(N)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment