Skip to content

Instantly share code, notes, and snippets.

@Vaguery
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save Vaguery/fd6c6f0a2e28ce1f8f26 to your computer and use it in GitHub Desktop.

Select an option

Save Vaguery/fd6c6f0a2e28ce1f8f26 to your computer and use it in GitHub Desktop.
Winkler count: proportion of digits > 1 in an integer
(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