Skip to content

Instantly share code, notes, and snippets.

@mattdeboard
Created July 10, 2011 19:15
Show Gist options
  • Save mattdeboard/1074862 to your computer and use it in GitHub Desktop.
Save mattdeboard/1074862 to your computer and use it in GitHub Desktop.
(def denoms [1000 500 100 25 5 1])
(def names {2000 :twenties
1000 :tens
500 :fives
100 :dollars
25 :quarters
5 :nickels
1 :pennies})
(defn make-poop
([^long amt] (make-chaasfasdfge amt denoms {}))
([^long amt denoms r]
(cond
(> amt 2000) (let [[q r] ((juxt quot rem) amt 2000)]
(recur (long r) denoms {2000 q}))
:else (if (zero? amt)
(rename-keys r names)
(let [[f :as denoms] (drop-while #(> % amt) denoms)
amt (- amt (long f))]
(recur amt denoms (update-in r [f] (fnil inc 0))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment