Project Euler - Problem9 └ Project Euler

Problem 9


25 January 2002

A Pythagorean triplet is a set of three natural numbers, a <b < c, for which,
                            a2 + b2 = c2
For example, 32 + 42 = 9 + 16 = 25 = 52.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.

문제 9.
┌ a2 + b2 = c2
└ a + b + c = 1000

a * b * c = ?


erlang code.

-module( problem9 ).
-export( [calc/0] ).

calc() ->
        mult( find_numbers() ).

find_numbers() ->
        [ {A, B, C} ||
                A <- lists:seq(1, 1000),
                B <- lists:seq(1, 1000),
                C <- lists:seq(1, 1000),
                A + B + C =:= 1000,
                A*+ B*=:= C*C,
                A<B,
                B<C
        ].

mult( [ {A, B, C} | _] ) ->
        A*B*C.



..... 최적화..  알고리즘..  그딴거 없는거다
실행하는데 10분정도 걸리지만 일단 값이 나왔으니..ㅋ


언젠가는 좀 보기좋게 고쳐야지.



덧글

댓글 입력 영역


통계 위젯 (블랙)

01
9
53794

이 이글루를 링크한 사람 (블랙)

11