lisp-random / picf.lisp

;; Copyright (c) 2011 Robert Smith
;; Inspired by Neil Bickford's <>

(defun rational-split (r)
  (multiple-value-list (truncate r)))

(defun rational->cf (r)
     :for proper := (rational-split r)
     :collect (first proper)
     :until (zerop (second proper))
     :do (setf r (/ (second proper)))))

(defun pi-cf (file &optional (precision nil))
  (let* ((pi-digits-string
          (subseq (with-open-file (s file) (read-line s))
                  0 precision))
         (pi-digits (/ (parse-integer pi-digits-string)
                       (expt 10 (1- (or precision
                                        (length pi-digits-string)))))))
    (rational->cf pi-digits)))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.