From 24feecb51fa63de08d754a926ceae502ba7479ce Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Sat, 24 Sep 2011 21:18:08 -0400 Subject: [PATCH] Excercise 005 --- e005.erl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 e005.erl diff --git a/e005.erl b/e005.erl new file mode 100644 index 0000000..bfb8912 --- /dev/null +++ b/e005.erl @@ -0,0 +1,25 @@ +% What is the smallest number divisible by each of the numbers 1 to 20? + +% 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. +% What is the smallest number that is evenly divisible by all of the numbers from 1 to 20? + +-module(e005). +-export([ + main/1 +]). + +divisible(N) -> + divisible(N, N, 1). +divisible(_, C, X) when C == 1 -> + X; +divisible(N, C, X) -> + if + X rem C == 0 -> + divisible(N, C - 1, X); + true -> + divisible(N, N, X + 1) + end. + +main(_) -> + io:format("Smallest number divisible by 1 to 10: ~w~n", [divisible(10)]), + io:format("Smallest number divisible by 1 to 10: ~w~n", [divisible(20)]).