[erlang-questions] Hi all here the RESUME for Pytagorians Numbers Algorithm!!!

Håkan Huss huss01@REDACTED
Mon Nov 15 10:38:41 CET 2010


2010/11/15 Gilberio Carmenates García <co7eb@REDACTED>:
>
> py3R NO returns the same than 'pythag1'     %% I just tries to put the
> Richard explanation in a
>                                               algorithm but, seems to me I
> was wrong here too.

I interpreted Richard's algorithm to be something along the lines of:

py3R(N)->
    [{A,B,C} ||
	A <- lists:seq(1, N div 2),
	B <- lists:seq(1, N - A),
	C <- [trunc(math:sqrt(A * A + B * B))],
        A + B + C =< N,
	A*A + B*B =:= C*C].

This version comes out on top when N is in the hundreds and above.
Below this it is omly matched by Morten's algorithm. I would argue
that Richard's is slightly less complex...

Regards,
/Håkan


More information about the erlang-questions mailing list