Fixing over-optimistic shortcut in factor.

This commit is contained in:
Alex Shinn 2014-06-10 19:57:52 +09:00
parent 347db3fb7d
commit 3ff62dc355
2 changed files with 4 additions and 1 deletions

View file

@ -181,10 +181,12 @@
(else
(let lp ((i 3) (n n) (limit limit) (res res))
(cond
((= n 1)
(reverse res))
((> i limit)
(reverse (cons n res)))
((zero? (remainder n i))
(lp i (quotient n i) (quotient limit i) (cons i res)))
(lp i (quotient n i) limit (cons i res)))
(else
(lp (+ i 2) n limit res))))))))))

View file

@ -68,6 +68,7 @@
(test '(2 5) (factor 10))
(test '(11) (factor 11))
(test '(2 2 3) (factor 12))
(test '(3 3 3 5 7) (factor 945))
(do ((i 3 (+ i 2)))
((>= i 101))