aboutsummaryrefslogtreecommitdiff
path: root/problem7.erl
blob: 1a6c2739729c12720b961c10443675d82fa0baba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
-module(problem7).
-export([solve/0]).

solve() -> gen_sized([2,3],10001).

gen_sized(List, Size) ->
	case length(List) of
		Size ->
			lists:nth(Size,List);
		_ ->
			gen_sized(gen_next(List),Size)
	end.
gen_next(List) ->
	gen_next(List, lists:max(List) + 1).
gen_next(List, Next) ->
	Q = will_divide(Next, List),
	if
		Q ->
			gen_next(List, Next + 1);
		true ->
			List ++ [Next]
	end.

will_divide(_, []) ->
	false;
will_divide(Num, [H|T]) ->
	if
		Num rem H =:= 0 ->
			true;
		true ->
			will_divide(Num, T)
	end.