added prolog e3
This commit is contained in:
parent
b9fa965567
commit
20a89cc870
|
@ -0,0 +1,13 @@
|
|||
append([],[],[]).
|
||||
append([],[H|T], [H|Acc]) :- append([], T, Acc).
|
||||
append([H|T], L, [H|Acc]) :- append(T, L, Acc).
|
||||
|
||||
factor(N, Divisor, [N]) :- N is 1; Divisor >= N - 1.
|
||||
factor(N, Divisor, Res) :- 0 is N rem Divisor, N1 is N/Divisor, factor(N1, 2, N1F), factor(Divisor, 2, DF), append(N1F, DF, Res).
|
||||
factor(N, Divisor, Res) :- N rem Divisor > 0, D2 is Divisor + 1, factor(N, D2, Res).
|
||||
|
||||
max([], TMax, TMax).
|
||||
max([H|T], TMax, M) :- H > TMax, max(T, H, M).
|
||||
max([H|T], TMax, M) :- max(T, TMax, M).
|
||||
|
||||
e3(Highest) :- factor(600851475143, 2, Factors), max(Factors, 0, Highest).
|
Loading…
Reference in New Issue