Created
June 11, 2010 20:49
-
-
Save juergenhoetzel/435032 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(defn calc-slice-count [thing] | |
"Calculates the number of possible slices using the formula: | |
(n + r - 1)! | |
------------ | |
r!(n - 1)! | |
where n is (count thing) and r is 2" | |
(let [! #(reduce * (take % (iterate inc 1))) | |
n (count thing) | |
r 2] | |
(/ (! (- (+ n r) 1)) | |
(* (! r) (! (- n 1)))))) | |
(extend-type String | |
Sliceable | |
(slice [this s e] (.substring this s (inc e))) | |
(sliceCount [this] (calc-slice-count this))) | |
(slice "abc" 0 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment