From 4d2e456eceb34a3406a1bd1e71330b3c7d89ad07 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Fri, 23 Sep 2011 22:15:48 -0400 Subject: [PATCH] Starting an erlang branch, starting with #001 --- e001.erl | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 e001.erl diff --git a/e001.erl b/e001.erl new file mode 100644 index 0000000..cb4b917 --- /dev/null +++ b/e001.erl @@ -0,0 +1,27 @@ +% Add all the natural numbers below one thousand that are multiples of 3 or 5. + +% If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. +% Find the sum of all the multiples of 3 or 5 below 1000. + +-module(e001). +-export([ + main/1 + ]). + +sum(3) -> + 0; +sum(Max) -> + N = Max - 1, + if + N rem 3 == 0 -> + A = N; + N rem 5 == 0 -> + A = N; + true -> + A = 0 + end, + sum(N) + A. + +main(_) -> + io:format("Sum of < 10: ~w~n", [sum(10)]), + io:format("Sum of < 1000: ~w~n", [sum(1000)]).