mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-20 14:19:18 +02:00
Fixing bug in factor.
This commit is contained in:
parent
5731ff73f7
commit
d382e92b14
2 changed files with 4 additions and 3 deletions
|
@ -171,15 +171,14 @@
|
|||
(list n))
|
||||
(else
|
||||
(let lp ((n n)
|
||||
(limit (exact (ceiling (sqrt n))))
|
||||
(res (list)))
|
||||
(cond
|
||||
((even? n)
|
||||
(lp (quotient n 2) (quotient limit 2) (cons 2 res)))
|
||||
(lp (quotient n 2) (cons 2 res)))
|
||||
((= n 1)
|
||||
(reverse res))
|
||||
(else
|
||||
(let lp ((i 3) (n n) (limit limit) (res res))
|
||||
(let lp ((i 3) (n n) (limit (exact (ceiling (sqrt n)))) (res res))
|
||||
(cond
|
||||
((= n 1)
|
||||
(reverse res))
|
||||
|
|
|
@ -68,6 +68,8 @@
|
|||
(test '(2 5) (factor 10))
|
||||
(test '(11) (factor 11))
|
||||
(test '(2 2 3) (factor 12))
|
||||
(test '(2 3 3) (factor 18))
|
||||
(test '(2 2 2 3 3) (factor 72))
|
||||
(test '(3 3 3 5 7) (factor 945))
|
||||
|
||||
(test 975 (aliquot 945))
|
||||
|
|
Loading…
Add table
Reference in a new issue