aboutsummaryrefslogtreecommitdiff
path: root/problem99.erl
blob: 445b767abba539db988f5b5c64cdf72bc3b1087c (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
-module(problem99).
-export([pow/2,solve/0]).
-import(problem99a,[getpairs/0]).

solve() ->
	work(getpairs(),[]).

work([],L) ->
	maxn(L);
work([{A,B}|T],L) ->
	work(T,[round(pow(A,B))|L]).

maxn(L) ->
	mwork(1,lists:reverse(L),1,0).

mwork(_,[],M,_) ->
	M;
mwork(N,[H|T],M,O) ->
	if
		H > O ->
			mwork(N+1,T,N,H);
		true ->
			mwork(N+1,T,M,O)
	end.

pow(X, N) when is_integer(N), N >= 0 -> pow(X, N, 1).

pow(_, 0, P) -> P;
pow(X, N, A) -> pow(X, N-1, A*X).