Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 73ddabc88b
Fetching contributors…

Cannot retrieve contributors at this time

18 lines (11 sloc) 0.302 kb
-module(sum).
-export([sum/1, sum2/1, sum/2]).
sum(0) -> 0;
sum(N) -> N + sum(N-1).
sum2(N) -> sum2_acc(0, N).
sum2_acc(D, 0) -> D;
sum2_acc(D, N) -> sum2_acc(D + N, N - 1).
sum(N,N) -> N;
sum(N,M) -> sum3_acc(0, N, M).
sum3_acc(D, N, N) -> D + N;
sum3_acc(D, N, M) -> sum3_acc(D + M, N, M - 1).
Jump to Line
Something went wrong with that request. Please try again.