Skip to content

Instantly share code, notes, and snippets.

@leontastic
Created January 26, 2014 22:58
Show Gist options
  • Save leontastic/8640592 to your computer and use it in GitHub Desktop.
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.
; 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