Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Additive-primes/Common-Lisp/additive-primes.lisp
Normal file
19
Task/Additive-primes/Common-Lisp/additive-primes.lisp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
(defun sum-of-digits (n)
|
||||
"Return the sum of the digits of a number"
|
||||
(do* ((sum 0 (+ sum rem))
|
||||
rem )
|
||||
((zerop n) sum)
|
||||
(multiple-value-setq (n rem) (floor n 10)) ))
|
||||
|
||||
(defun additive-primep (n)
|
||||
(and (primep n) (primep (sum-of-digits n))) )
|
||||
|
||||
|
||||
; To test if a number is prime we can use a number of different methods. Here I use Wilson's Theorem (see Primality by Wilson's theorem):
|
||||
|
||||
(defun primep (n)
|
||||
(unless (zerop n)
|
||||
(zerop (mod (1+ (factorial (1- n))) n)) ))
|
||||
|
||||
(defun factorial (n)
|
||||
(if (< n 2) 1 (* n (factorial (1- n)))) )
|
||||
Loading…
Add table
Add a link
Reference in a new issue