started challenge 3 with erlang
This commit is contained in:
parent
589397355b
commit
b9fa965567
|
@ -0,0 +1,18 @@
|
||||||
|
-module(e3).
|
||||||
|
-export([e3/0, factor/3]).
|
||||||
|
|
||||||
|
% e3 get largest prime factor
|
||||||
|
|
||||||
|
% returns list of prime factors
|
||||||
|
factor(N, Factors, Divisor) when N == 1; Divisor >= N-1 -> %io:format("done ~p/~p\n", [N, Divisor]),
|
||||||
|
[N]++Factors;
|
||||||
|
factor(N, Factors, Divisor) when N rem Divisor == 0 -> %io:format("match ~p/~p\n", [N, Divisor]),
|
||||||
|
Factors++factor(Divisor, [], 2) ++ factor(trunc(N/Divisor), [], 2);
|
||||||
|
factor(N, Factors, Divisor) -> %{io:format("inc ~p/~p\n", [N, Divisor]),}%
|
||||||
|
factor(N, Factors, Divisor+1).
|
||||||
|
|
||||||
|
max([], Max) -> Max;
|
||||||
|
max([H|T], Max) when H > Max -> max(T, H);
|
||||||
|
max([H|T], Max) -> max(T, Max).
|
||||||
|
|
||||||
|
e3() -> max(factor(600851475143, [], 2), 0).
|
Loading…
Reference in New Issue