Last active
June 10, 2019 19:38
-
-
Save kupp1/d8d032a7b93e4c5aad35427c261534a7 to your computer and use it in GitHub Desktop.
factorization
This file contains hidden or 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
(defun factorize(n) | |
(setq facts '() d 2) | |
(loop while (<= (* d d) n) do | |
(loop while (= 0 (rem n d)) do | |
(setq n (/ n d)) | |
(setq facts (push d facts))) | |
(setq d (1+ d))) | |
(when (/= n 1) | |
(setq facts (push n facts))) | |
facts) | |
(format t "~A" (factorize 4352562356623623)) ;on my pc takes 0m0.594s | |
(bye) |
This file contains hidden or 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
(defun factorize(n) | |
(if (/= n 1) | |
(progn | |
(setq d 2) | |
(loop while (/= (rem n d) 0) do | |
(setq d (1+ d))) | |
(setq n (/ n d)) | |
(cons d (factorize n))))) | |
(format t "~A "(factorize 4352562356623623)) ;on my pc takes 0m2.335s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment