Anonymous user
Factors of an integer: Difference between revisions
→fac.m
m (→{{header|REXX}}: split a joined line. -- ~~~~) |
(→fac.m) |
||
Line 1,324:
factor(N, Factors) :-
Limit = float.truncate_to_int(math.sqrt(float(N))),
factor(N, 2, Limit, [], Unsorted),
list.sort_and_remove_dups([1, N | Unsorted], Factors).
:- pred factor(int::in, int::in, int::in, list(int)::in, list(int)::out) is det.
factor(N, X, Limit, !Accumulator) :-
( if X > Limit
then
else ( if 0 = N mod X
then !:Accumulator = [X, N / X |
else
factor(N, X + 1, Limit,
:- func factor(int::in) = (list(int)::out) is det.
factor(N) = Factors :- factor(N, Factors).
:- end_module fac.
</lang>
===Use and output===
|