Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as text by kburton ( 19 years ago )
-module(factor).
-export([fact/1]).
% c('factor').
% factor:fact(123456723456789).
fact(1) ->
[];
fact(N) ->
% io:format("~w
", [N]),
M = next_factor(N, 2, N rem 2),
[ M | fact(N div M) ].
% find the next factor
next_factor(_, M, 0) ->
M;
next_factor(N, N, _) ->
N;
next_factor(N, M, _) ->
next_factor(N, M+1, N rem (M+1)).
Revise this Paste