From 0d05c12cb9d056b29c74b8f12e15269b68e6d85d Mon Sep 17 00:00:00 2001 From: Nathan Lasseter Date: Wed, 7 Oct 2009 03:04:24 +0100 Subject: Problem 30 --- problem30.erl | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 problem30.erl 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). -- cgit v1.2.1