Created
December 8, 2011 18:58
-
-
Save Jach/1448054 to your computer and use it in GitHub Desktop.
Stuff from LOL translated into Clojure
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
; listing 1.4: group | |
(defn group [coll n] | |
(if (zero? n) | |
(throw (Exception. "zero length")) | |
(partition-all n coll))) | |
; listing 1.5: flatten | |
; built-in | |
; listing 1.6: fact-and-choose | |
(defn fact [x] | |
(loop [n x total 1] | |
(if (zero? n) | |
total | |
(recur (dec n) (* total n))))) | |
(defn choose [n r] | |
(/ (fact n) | |
(fact (- n r)) | |
(fact r))) | |
(def ncr choose) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment