%%% -*- mode: erlang -*-
%%% $Id: nestedloop.erlang,v 1.1 2001/05/15 07:00:27 doug Exp $
%%% http://www.bagley.org/~doug/shootout/

-module(nestedloop).
-export([main/1]).

main([Arg]) ->
    Num = list_to_integer(atom_to_list(Arg)),
    io:fwrite("~w\n", [loopA(Num, Num, 0)]),
    halt(0).


loopA(0, M, N) -> N;
loopA(I, M, N) -> loopA(I - 1, M, loopB(M, M, N)).

loopB(0, M, N) -> N;
loopB(I, M, N) -> loopB(I - 1, M, loopC(M, M, N)).

loopC(0, M, N) -> N;
loopC(I, M, N) -> loopC(I - 1, M, loopD(M, M, N)).

loopD(0, M, N) -> N;
loopD(I, M, N) -> loopD(I - 1, M, loopE(M, M, N)).

loopE(0, M, N) -> N;
loopE(I, M, N) -> loopE(I - 1, M, loopF(M, N)).

loopF(0, N) -> N;
loopF(I, N) -> loopF(I - 1, 1 + N).