diff options
Diffstat (limited to 'problem30.erl')
-rw-r--r-- | problem30.erl | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/problem30.erl b/problem30.erl new file mode 100644 index 0000000..7e40d91 --- /dev/null +++ b/problem30.erl @@ -0,0 +1,32 @@ +-module(problem30). +-export([solve/0]). + +solve() -> + Seq = lists:seq(2, 9999999), +% Yeah, that's an arbitrary upper limit =P + lists:sum( + lists:filter( + fun(X) -> num(X) end, + Seq + ) + ). + +num(Int) -> + Int =:= lists:sum( + lists:map( + fun(X) -> pow(X, 5) end, + itol(Int) + ) + ). + +itol(Int) -> + Str = integer_to_list(Int), + lists:map( + fun(X) -> (X - 48) end, + Str + ). + +pow(B, 1) -> + B; +pow(B, E) -> + B * pow(B, E-1). |