From 0248ed34ce3d05228bc5084669c3a27933be0c2e Mon Sep 17 00:00:00 2001 From: Nathan Lasseter Date: Sun, 4 Oct 2009 00:56:56 +0100 Subject: first commit --- problem6.erl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 problem6.erl (limited to 'problem6.erl') diff --git a/problem6.erl b/problem6.erl new file mode 100755 index 0000000..34a0a01 --- /dev/null +++ b/problem6.erl @@ -0,0 +1,22 @@ +-module(problem6). +-export([solve/0]). + +solve() -> diff(lists:seq(1,100)). + +diff(List) -> + M = sum_of_squares(List), + N = square_of_sum(List), + if + M < N -> + N - M; + M > N -> + M - N; + true -> + 0 + end. + +sum_of_squares(List) -> + lists:sum(lists:map(fun(X) -> X*X end, List)). +square_of_sum(List) -> + O = lists:sum(List), + O*O. -- cgit v1.2.1