-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
20 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
% factors(N,Fs) <- Fs is the list of prime factors of N | ||
factors(1,[1]). | ||
factors(X,[Factor|Fs]) :- | ||
X > 1, | ||
between(2,X,Factor), % generate candidate factor, lowest first | ||
(X mod Factor) =:= 0, % test Factor is divisor of X | ||
!, % if so, stop generating! | ||
Rem is X // Factor, % proceed with remainder | ||
factors(Rem,Fs). | ||
|
||
/** <examples> | ||
?-factors(27,Fs). | ||
?-factors(28,Fs). | ||
?-factors(29,Fs). | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters