Skip to content

Instantly share code, notes, and snippets.

@lispm
Created July 23, 2018 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lispm/a8bfc8997c6a2a5565a73e0aa4560826 to your computer and use it in GitHub Desktop.
Save lispm/a8bfc8997c6a2a5565a73e0aa4560826 to your computer and use it in GitHub Desktop.
(defun divisors (n &aux (divisors (list 1)))
(etypecase n
((integer * 1) nil)
((integer 2 *)
(loop with q and r
for i from 2 to (isqrt n)
do (setf (values q r) (truncate n i))
when (zerop r) do (push q divisors) and do (push i divisors))
(if (and (second divisors)
(= (first divisors) (second divisors)))
(rest divisors)
divisors))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment