HomeAboutCodePastes
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordieggsy <dieggsy@pm.me>2021-04-26 16:57:18 -0400
committerdieggsy <dieggsy@pm.me>2021-04-26 16:57:18 -0400
commit0eefb230650ae97dd9ac5934ff656329156fc386 (patch)
treef11171f57d4e4421f4457a6157931a411dc32280
parent9f0f91ab4e71b2e99158c4843d1e866b337f05d2 (diff)
downloadproject-euler-0eefb230650ae97dd9ac5934ff656329156fc386.tar.gz
Ensure lisp miller rabin doesn't trip up on zero
-rw-r--r--sbcl/numbers.lisp3
1 files changed, 2 insertions, 1 deletions
diff --git a/sbcl/numbers.lisp b/sbcl/numbers.lisp
index dc12a5a..717610d 100644
--- a/sbcl/numbers.lisp
+++ b/sbcl/numbers.lisp
@@ -52,7 +52,8 @@
(defun miller-rabin (n k)
"Test N for primality by performing the Miller-Rabin test K times.
Return NIL if N is composite, and T if N is probably prime."
- (cond ((= n 1) nil)
+ (cond ((zerop n) nil)
+ ((= n 1) nil)
((< n 4) t)
((evenp n) nil)
(t