diff options
author | Nathan Lasseter <nathan.je.lasseter@googlemail.com> | 2009-10-04 00:56:56 +0100 |
---|---|---|
committer | Nathan Lasseter <nathan.je.lasseter@googlemail.com> | 2009-10-04 00:56:56 +0100 |
commit | 0248ed34ce3d05228bc5084669c3a27933be0c2e (patch) | |
tree | b9c4990344b0863a2af851b5917c49f3a5f03e6b /problem10.erl | |
parent | 00686037d57eb0a0d5eba6eeb6fcc9692e8b59f6 (diff) |
first commit
Diffstat (limited to 'problem10.erl')
-rwxr-xr-x | problem10.erl | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/problem10.erl b/problem10.erl new file mode 100755 index 0000000..0b2c10f --- /dev/null +++ b/problem10.erl @@ -0,0 +1,34 @@ +-module(problem10). +-export([solve/0]). + +solve() -> gen_list([2,3],2000000). + +gen_list(List,Max) -> + O = gen_next(List), + if + O > Max -> + lists:sum(List); + true -> + gen_list(List++[O],Max) + 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 -> + Next + end. + +will_divide(_, []) -> + false; +will_divide(Num, [H|T]) -> + if + Num rem H =:= 0 -> + true; + true -> + will_divide(Num, T) + end. |