From 0248ed34ce3d05228bc5084669c3a27933be0c2e Mon Sep 17 00:00:00 2001 From: Nathan Lasseter Date: Sun, 4 Oct 2009 00:56:56 +0100 Subject: first commit --- problem21.erl | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 problem21.erl (limited to 'problem21.erl') diff --git a/problem21.erl b/problem21.erl new file mode 100644 index 0000000..1661801 --- /dev/null +++ b/problem21.erl @@ -0,0 +1,26 @@ +-module(problem21). +-export([solve/0]). + +solve() -> + L = test(1, []), + pairs(L, 0). + +test(10000, L) -> + L; +test(A,L) -> + D = [X || X <- lists:seq(1, erlang:trunc(math:sqrt(A))), (A rem X) =:= 0], + E = [A div Y || Y <- D], + F = sets:to_list(sets:from_list((D ++ E) -- [A])), + G = lists:sum(F), + test(A+1, [{A,G}|L]). + +pairs([_], S) -> + S; +pairs([{A,B}|T], S) -> + M = lists:member({B, A}, T), + if + M -> + pairs(T, S+A+B); + true -> + pairs(T, S) + end. -- cgit v1.2.1