Skip to content

Commit

Permalink
Removed the digit manipulation functions.
Browse files Browse the repository at this point in the history
See the library cl-numerics.
  • Loading branch information
smithzvk committed May 31, 2012
1 parent 79382e4 commit 6db4e08
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 47 deletions.
46 changes: 0 additions & 46 deletions number-theory.lisp
Expand Up @@ -124,49 +124,3 @@ prime (we use MILLER-RABIN for the test here)."
;;; Define some common name interfaces
(defwrapper factor factor-trial-division)
(defwrapper coprime-factor coprime-factor-trial-division)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Dealing with digits ;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(with-compilation-unit (:override nil)
(defun n-digits (n)
(funcall
(alambda (n count)
(cond ((= n 0) count)
(t (self (floor n 10) (1+ count))) ))
n 0 ))
(defun get-digit (n m)
(cond ((= m 0) (mod n 10))
(t (get-digit (floor n 10) (1- m))) ))
(defun digits<-number (n)
(declare (type integer n))
(funcall
(alambda (n m ret)
(cond ((= m 1) (cons (mod n 10) ret))
(t (self (floor n 10) (1- m) (cons (mod n 10) ret))) ))
n (n-digits n) nil ))
(defun number<-digits (digits)
(declare (type list digits))
(funcall
(alambda (digits pow tot)
(cond ((null digits) tot)
(t (self (cdr digits) (1+ pow)
(+ tot (* (car digits) (expt 10 pow))) ))))
(reverse digits) 0 0) ) )

;;; Examples

;; (n-digits 321)
;; (n-digits (floor 1d100))
;; (n-digits (expt 2 32)) ; 2^32 ~= 4e9

;; (mapcar #'(lambda (n) (get-digit 12345 n)) '(0 1 2 3 4))

;; (digits<-number 12345)
;; (number<-digits (digits<-number 54321))

;;

1 change: 0 additions & 1 deletion package.lisp
Expand Up @@ -96,7 +96,6 @@
;;; Number-theory
#:*-mod #:expt-mod
#:miller-rabin #:gen-prime
#:n-digits #:get-digit #:digits<-number #:number<-digits
#:prime?
#:factor-trial-division #:coprime-factor-trial-division
#:factor #:coprime-factor
Expand Down

0 comments on commit 6db4e08

Please sign in to comment.