aboutsummaryrefslogtreecommitdiff
path: root/problem30.erl
blob: 7e40d91ea43297efd9b1a0533aff4cc300bf6d58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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).