Created
October 11, 2017 01:06
-
-
Save sjl/91ece4e0db42a6bb8b611a6c812310e6 to your computer and use it in GitHub Desktop.
Project Euler #69 in uLisp (runnable on Ardunio Zero or Due)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun dividesp (n d) | |
(= n (* d (/ n d)))) | |
(defun brute-force-prime-p (n) | |
(let ((d 3)) | |
(loop (cond | |
((> (* d d) n) (return t)) | |
((dividesp n d) (return nil)) | |
(t (incf d 2)))))) | |
(defun primep (n) | |
(cond | |
((<= n 1) nil) | |
((= n 2) t) | |
((evenp n) nil) | |
(t (brute-force-prime-p n)))) | |
(defun next-prime (n) | |
(if (= n 2) | |
3 | |
(loop (incf n 2) | |
(when (primep n) | |
(return n))))) | |
(defun p69 () | |
(let ((result 1) | |
(n 1) | |
(p 2)) | |
(loop | |
(setf n (* n p)) | |
(if (> n 1000000) | |
(return result) | |
(progn (setf result (* result p)) | |
(setf p (next-prime p))))))) | |
(defun dump-functions () | |
(dolist | |
(symbol (globals)) | |
(let ((body (eval symbol))) | |
(when (and (listp body) | |
(eq (car body) 'lambda)) | |
(pprint (append (list 'defun symbol) | |
(cdr body))) | |
(terpri))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment