Skip to content

Instantly share code, notes, and snippets.

@kupp1
Last active June 10, 2019 19:38
Show Gist options
  • Save kupp1/d8d032a7b93e4c5aad35427c261534a7 to your computer and use it in GitHub Desktop.
Save kupp1/d8d032a7b93e4c5aad35427c261534a7 to your computer and use it in GitHub Desktop.
factorization
(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)
(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