From 0248ed34ce3d05228bc5084669c3a27933be0c2e Mon Sep 17 00:00:00 2001 From: Nathan Lasseter Date: Sun, 4 Oct 2009 00:56:56 +0100 Subject: first commit --- problem7.erl | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 problem7.erl (limited to 'problem7.erl') diff --git a/problem7.erl b/problem7.erl new file mode 100755 index 0000000..1a6c273 --- /dev/null +++ b/problem7.erl @@ -0,0 +1,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. -- cgit v1.2.1