Last active
August 29, 2015 14:16
-
-
Save Vaguery/fd6c6f0a2e28ce1f8f26 to your computer and use it in GitHub Desktop.
Winkler count: proportion of digits > 1 in an integer
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 count-digits [num] (count (str num))) | |
| (defn count-not-01 [num] | |
| (let [counts (frequencies (re-seq #"\d" (str num)))] | |
| (- 1 | |
| (/ (+ (get counts "0" 0) | |
| (get counts "1" 0)) | |
| (count-digits num))))) | |
| (count-not-01 118120) ;; => 1/3 | |
| (count-not-01 10001010001) ;; => 0 | |
| (count-not-01 7788326532) ;; => 1 | |
| (count-not-01 11111111111111111111111111111888888888888888888888888888888888888888888888888N) ;; => 44/77 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment