Created
January 26, 2014 22:58
-
-
Save leontastic/8640592 to your computer and use it in GitHub Desktop.
A clone of the Racket "divisors" function available in the "math/number-theory" module.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; factors: Int -> (listof Int) | |
; (factors a) produces a list of all positive factors of a, including 1 and itself. | |
(define (factors a) | |
(define b (abs a)) | |
(filter (lambda (n) (= (remainder b n) 0)) | |
(build-list b (lambda (y) (+ 1 y))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment