factorize-scheme   scheme


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/examples/contrib/word_count.xtm

Implementation

(define factorize-scheme
  (lambda (n)
    (let loop ((n n)
               (d 2)
               (factors '()))
      (if (< n 2)
          (cons n factors)
          (if (< d n)
              (if (= (modulo n d) 0)
                  (loop (real->integer (/ n d))
                        d
                        (cons d factors))
                  (loop n
                        (if (= d 2)
                            (set! d 3)
                            (set! d (+ d 2)))
                        factors))
              factors)))))


Back to Index