Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -0,0 +1,25 @@
|
|||
(ql:quickload '(lparallel))
|
||||
|
||||
(setf lparallel:*kernel* (lparallel:make-kernel 4)) ;; Configure for your system.
|
||||
|
||||
(defun factor (n &optional (acc '()))
|
||||
(when (> n 1)
|
||||
(loop with max-d = (isqrt n)
|
||||
for d = 2 then (if (evenp d) (1+ d) (+ d 2)) do
|
||||
(cond ((> d max-d) (return (cons (list n 1) acc)))
|
||||
((zerop (rem n d))
|
||||
(return (factor (truncate n d)
|
||||
(if (eq d (caar acc))
|
||||
(cons
|
||||
(list (caar acc) (1+ (cadar acc)))
|
||||
(cdr acc))
|
||||
(cons (list d 1) acc)))))))))
|
||||
|
||||
(defun max-minimum-factor (numbers)
|
||||
(lparallel:pmap-reduce
|
||||
(lambda (n) (cons n (apply #'min (mapcar #'car (factor n)))))
|
||||
(lambda (a b) (if (> (cdr a) (cdr b)) a b))
|
||||
numbers))
|
||||
|
||||
(defun print-max-factor (pair)
|
||||
(format t "~a has the largest miniumum factor ~a~%" (car pair) (cdr pair)))
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
CL-USER> (print-max-factor (max-minimum-factor '(12757923 12878611 12878893 12757923 15808973 15780709 197622519)))
|
||||
12878893 has the largest miniumum factor 47
|
||||
Loading…
Add table
Add a link
Reference in a new issue