-
-
Save ctrlrsf/12ea523e63539f166375 to your computer and use it in GitHub Desktop.
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
(defn numofzeros | |
"Returns number of zeros in a number. Eg, 1000 returns 3." | |
[input] | |
(count (filter #(= \0 %) (str input)))) | |
(defn countall | |
"Count all number of zeros contained in all numbers between 0 and n (inclusive) | |
Returns map of number of zeros in n and sum of all combined zeros" | |
[n] | |
(let [lastnumzeros (numofzeros n) | |
sum (reduce (fn [acc x] (+ acc (numofzeros x))) 0 (range (inc n)))] | |
{:zeros lastnumzeros :sum sum})) | |
(println (countall (long 1e9)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment