aboutsummaryrefslogtreecommitdiff
path: root/problem30.erl
diff options
context:
space:
mode:
authorNathan Lasseter <nathan.je.lasseter@googlemail.com>2009-10-07 03:04:24 +0100
committerNathan Lasseter <nathan.je.lasseter@googlemail.com>2009-10-07 03:04:24 +0100
commit0d05c12cb9d056b29c74b8f12e15269b68e6d85d (patch)
treeb516f2bfa1b8b525f75cfbb82004a851f1df5b00 /problem30.erl
parent01133025dc69824c47e56a914f289c96bc970e1b (diff)
Problem 30HEADmaster
Diffstat (limited to 'problem30.erl')
-rw-r--r--problem30.erl32
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).