Anonymous user
Factors of an integer: Difference between revisions
→fac.m: Replaced implementation with a tail-recursive implementation that does magic.
m (→fac.m) |
(→fac.m: Replaced implementation with a tail-recursive implementation that does magic.) |
||
Line 1,287:
:- implementation.
:- import_module float, getopt, int, list, math, string.
main(!IO) :-
Line 1,302:
factor(N, L) :-
Limit = float.truncate_to_int(math.sqrt(float(N))),
factor(N, 2, Limit,
list.sort_and_remove_dups([1, N | L0], L).
:- pred factor(int::in, int::in, int
factor(N, X, Z,
(X > Z ->
;
(0 = N mod X ->
;
),
factor(N, X + 1, Z, L)
).
|