When condition problem (probably newbie question).

Joe Armstrong <>
Mon Dec 21 10:07:06 CET 1998


> So the resulting code could look like:
> 
> pow(N,0) -> io:write({pow,N,0}), io:nl(), 1;
> pow(N,1) -> N;
> pow(N,M) when M rem 2 == 0 ->
>   io:write({powNeven,N,M}), io:nl(),
>   X = pow(N,M div 2), X * X;
> pow(N,M) ->  % M is odd, > 1
>   X = pow(N,M-1),
>   X*N.
> 



If you look in http://www.erlang.org/examples/examples-2.0.html

And in http://www.erlang.org/examples/examples-2.0.tgz

You'll find 3 modules:

    lin.erl  -  this   contains  some  simple   functions  for  linear
algebra. (including pow/2)

    primes.erl - Contains routines for generating large primes.

    rsa_key.erl - Shows how a public key crypto system could have been
implemented in Erlang.

--
Joe Armstrong  Computer Science Laboratory  +46 8 719 9452
AT2/ETX/DN/SU  Ericsson Telecom SE-126 25 Stockholm Sweden 
    http://www.ericsson.se/cslab/~joe 




More information about the erlang-questions mailing list