Integer long division: Difference between revisions

m
(Created the task of Long Division)
 
Line 17:
; ($/ 1 17) => 588235294117647 ; 16
(assert (and (integerp a) (integerp b) (not (zerop b))))
(do* (c (i0 (1+ (max (factor-multiplicity b 2) (factor-multiplicity b 5)))) ; the position which marks the beginning of the period
(do* (c
(i0 (1+ (max (factor-multiplicity b 2) (factor-multiplicity b 5)))) ; the position which marks the beginning of the period
(r a (* 10 r)) ; remainder
(i 0 (1+ i)) ; iterations counter
Line 25 ⟶ 24:
(multiple-value-setq (c r) (floor r b))
(princ c) ))
 
 
(defun factor-multiplicity (n factor)
"Return how many times the factor is contained in n"
; (factor-multiplicity 12 2) => 2
(do* ((i 0 (1+ i))
(n (/ n factor) (/ n factor)) )
((not (integerp n)) i)
() ))
 
</lang>
{{out}}
47

edits