aboutsummaryrefslogtreecommitdiff
path: root/problem56.erl
blob: 416bdbd0eaec634c56218a724601ba485d030feb (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
-module(problem56).
-export([solve/0]).

solve() ->
	lists:max(gen_sums(99)).

gen_sums(M) ->
	[digital_sum(X) || X <- gen_list(M)].

gen_list(M) ->
	L = lists:seq(1,M),
	[pow(A,B) || A <- L, B <- L].

digital_sum(Number) when is_integer(Number) ->
	digital_sum(integer_to_list(Number));
digital_sum([]) ->
	0;
digital_sum([H|T]) ->
	(H-48) + digital_sum(T).

pow(_,0) ->
	1;
pow(B,1) ->
	B;
pow(B,E) ->
	B * pow(B,E-1).