diff options
Diffstat (limited to 'problem42.erl')
-rwxr-xr-x | problem42.erl | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/problem42.erl b/problem42.erl new file mode 100755 index 0000000..1982f2b --- /dev/null +++ b/problem42.erl @@ -0,0 +1,29 @@ +-module(problem42). +-export([solve/0]). +-import(problem42a,[getwords/0]). + +solve() -> + V = [value(X) || X <- getwords()], + T = numbers(lists:max(V), 1, [1]), + length([Y || Y <- V, lists:member(Y,T)]). + +numbers(M,N,L) -> + O = lists:max(L), + if + O >= M -> + L; + true -> + numbers(M,N+1,[((N*(N+1)) div 2) | L]) + end. + +value([H|T]) -> + if + (H > 64) and (H < 91) -> + (H - 64) + value(T); + (H > 96) and (H < 123) -> + (H - 96) + value(T); + true -> + value(T) + end; +value([]) -> + 0. |