R2DeltaSquared

    • Arbitrary Precision Long Division

      • 01/26/12
      • 5:01PM
      ;So I got Long Division Working
      ;I was reading about the ratio
      ;1 / 998001 which expands to ever 3 digit sequence in order
      ;There was sample code in Python, but I thought I would 
      ;write it in Common Lisp instead
      ;You will need a flatten procedure Doug Hoyte has a nice one posted
      ;(long-div 1 / 998001 3000) is makes interesting if long output
      
      (defun long-div (dividend divisor depth)
          (cond
              ((> depth 0)
                  (flatten (list
                  (truncate (/ dividend divisor))
                  (long-div (* 10 (mod dividend divisor)) divisor (- depth 1)))))
           (t ())))