Skip to content

Instantly share code, notes, and snippets.

@lyuehh
Created January 27, 2013 09:51
Show Gist options
  • Save lyuehh/4647609 to your computer and use it in GitHub Desktop.
Save lyuehh/4647609 to your computer and use it in GitHub Desktop.
(define (factor n)
(if (= n 1)
1
(* n (factor (- n 1)))))
(define (factor2 n)
(factor-iter 1 1 n))
(define (factor-iter product counter max-count)
(if (> counter max-count)
product
(factor-iter (* product counter) (+ counter 1) max-count)))
(define (factor2 n)
(define (iter product counter)
(if (> counter n)
product
(iter (* product counter) (+ counter 1))))
(iter 1 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment