Skip to content

Instantly share code, notes, and snippets.

@KingCode
KingCode / gist:30894e53da19d712021906629cf1583c
Last active February 13, 2021 15:35
frequencies-by function
(defn frequencies-by
"Returns a map from distinct results of (f item) in coll
to a vector duple of all (k item) (if k is provided, or items otherwise)
with the same (f item) value, and the number of times (f item) appears.
"
([f coll]
(frequencies-by f nil coll))
([f k coll]
(persistent! ;; copied from clojure.core
See
https://gist.github.com/ericnormand/7174aaccc71025de86ddac77553f8595
How many digits?
Imagine you took all the integers between n and m (exclusive, n <
m) and concatenated them together. How many digits would you have?
Write a function that takes two numbers and returns how many
digits. Note that the numbers can get very big, so it is not
possible to build the string in the general case.