Skip to content

Instantly share code, notes, and snippets.

View cl-prime-number:inverse-factorize-from-prime.lisp
(defun inverse-factorize-from-prime (target &key (prime-series *prime-series*))
(if (null target)
1
(* (expt (lcar prime-series) (car target))
(inverse-factorize-from-prime (cdr target)
:prime-series (lcdr prime-series)))))
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:calc-GCD&calc-LCM.lisp
(defun calc-GCD (&rest nums)
(inverse-factorize-from-prime
(bundle-lists #'min
(mapcar #'factorize-in-prime nums))))
(defun calc-LCM (&rest nums)
(inverse-factorize-from-prime
(bundle-lists #'max
(mapcar #'factorize-in-prime nums))))
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])))
a[n-1])>)
(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]))
(filter-series
#'(lambda (val)
(< 0 (mod val factor)))
a[n-1]))>)
(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)))
t)))
View sample-rss-parser.ros
#!/bin/sh
#|-*- 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
#!/bin/sh
#|-*- 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
#!/bin/sh
#|-*- 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))
result))))
(reverse result)))