mirror of
https://github.com/correl/euler.git
synced 2024-11-23 19:19:53 +00:00
Excercise 005
This commit is contained in:
parent
5b86e3b132
commit
24feecb51f
1 changed files with 25 additions and 0 deletions
25
e005.erl
Normal file
25
e005.erl
Normal file
|
@ -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)]).
|
Loading…
Reference in a new issue