aboutsummaryrefslogtreecommitdiff
path: root/problem99.erl
diff options
context:
space:
mode:
authorNathan Lasseter <nathan.je.lasseter@googlemail.com>2009-10-04 00:56:56 +0100
committerNathan Lasseter <nathan.je.lasseter@googlemail.com>2009-10-04 00:56:56 +0100
commit0248ed34ce3d05228bc5084669c3a27933be0c2e (patch)
treeb9c4990344b0863a2af851b5917c49f3a5f03e6b /problem99.erl
parent00686037d57eb0a0d5eba6eeb6fcc9692e8b59f6 (diff)
first commit
Diffstat (limited to 'problem99.erl')
-rwxr-xr-xproblem99.erl29
1 files changed, 29 insertions, 0 deletions
diff --git a/problem99.erl b/problem99.erl
new file mode 100755
index 0000000..445b767
--- /dev/null
+++ b/problem99.erl
@@ -0,0 +1,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).