Skip to content

Instantly share code, notes, and snippets.

View Sieve-of-Eratosthenes-1.lisp
(defparameter *sieve* #<a[n] =
#<b[k] = (+ k 2) >, (filter-series
#'(lambda (val)
(< 0 (mod val a[n-1][0])))
(defparameter *primes* #<a[n] = *sieve*[n][0]>)
View Sieve-of-Eratosthenes-2.lisp
(defparameter *sieve* #<a[n] =
#<b[k] = 2, (1+ (* k 2)) >, (let ((factor a[n-1][0]))
#'(lambda (val)
(< 0 (mod val factor)))
(defparameter *primes* #<a[n] = *sieve*[n][0]>)
View check-series-mod.lisp
(defun check-series-mod (target a n)
(cond ((< target 2) nil)
((= target 2) t)
(t (do-series (val a to (1- n))
(if (= (mod target val) 0)
(return-from check-series-mod nil))
(if (> (expt val 2) target)
(return-from check-series-mod t)))
View cl-prime-number:factorize-in-prime.lisp
(defun factorize-in-prime (target &key (prime-series *prime-series*))
(if (eq target 1)
(return-from factorize-in-prime nil))
(let ((factor (lcar prime-series)))
(cons (loop while (= (mod target factor) 0)
count t
do (setf target (/ target factor)))
(factorize-in-prime target :prime-series (lcdr prime-series)))))
View cl-prime-number:inverse-factorize-from-prime.lisp
(defun inverse-factorize-from-prime (target &key (prime-series *prime-series*))
(if (null target)
(* (expt (lcar prime-series) (car target))
(inverse-factorize-from-prime (cdr target)
:prime-series (lcdr prime-series)))))
View cl-prime-number:calc-GCD&calc-LCM.lisp
(defun calc-GCD (&rest nums)
(bundle-lists #'min
(mapcar #'factorize-in-prime nums))))
(defun calc-LCM (&rest nums)
(bundle-lists #'max
(mapcar #'factorize-in-prime nums))))
View sample-rss-parser.ros
#|-*- mode:lisp -*-|#
exec ros -Q -- $0 "$@"
(defparameter *depend-on* '(:dexador :cxml))
(eval-when (:execute)
(dolist (target *depend-on*)
(ql:quickload target)))
View sample-read-macro-1.ros
#|-*- mode:lisp -*-|#
exec ros +Q -- $0 "$@"
(defun do-nothing (&rest rest)
(declare (ignore rest)))
(defun make-list-reader (stream &rest rest)
View test-let-read-eval-order.ros
#|-*- mode:lisp -*-|#
exec ros +Q -- $0 "$@"
(defun set-delimiter-with-print (char)
(set-macro-character char #'(lambda (&rest rest)
(declare (ignore rest))))
(print "set delimiter"))
View safe-convert-raw-data-one-line.lisp
(defun reconstruct-list (lst fn-elem)
(labels ((rec (result rest)
(if rest
(dolist (elem rest)
(setf result
(cons (if (listp elem)
(rec nil elem)
(funcall fn-elem elem))
(reverse result)))