-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpe027.lisp
32 lines (27 loc) · 962 Bytes
/
pe027.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(in-package :clamp)
;; https://github.com/smithzvk/cl-primality
(use-package :cl-primality)
(defparameter lower-a* -999 "The lower bound on a.")
(defparameter lower-b* -999 "The lower bound on b.")
(defparameter upper-a* 999 "The upper bound on a.")
(defparameter upper-b* 999 "The upper bound on b.")
(def quad-val (a b n)
"Returns the value of the quadratic [N^2 + AN + B]."
(+ (* n n) (* a n) b))
(def num-prime (a b)
"Returns the number of consecutive prime numbers this quadratic
generates."
(loop for n from 0
for val = (quad-val a b n)
while (and (> val 0) (miller-rabin val 1d-10))
finally (return n)))
(def solve ()
"Solves PE problem 27."
(ret result 0
(let best-score 0
(upto a lower-a* upper-a*
(upto b lower-b* upper-b*
(let next-score (num-prime a b)
(when (> next-score best-score)
(= best-score next-score
result (* a b)))))))))