Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Last active December 17, 2015 18:59
Show Gist options
  • Select an option

  • Save thinkphp/5657329 to your computer and use it in GitHub Desktop.

Select an option

Save thinkphp/5657329 to your computer and use it in GitHub Desktop.
Calculating prime factors in Common Lisp
;Adrian Statescu <mergesortv@gmail.com>
;(factors 8)
;(2 3)
(defun factors (N)
(let ((R))
(do ((x N)(c 0)(i 2 (+ i 1))) ((= x 1) R)
(setf c 0)
(if (equal (REM x i) 0)
(do () ((> (REM x i) 0))
(setf c (+ c 1))
(setf x (floor (/ x i)))
)
)
(if (> c 0) (and (setf R (cons c R))(setf R (cons i R)))
)
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment