2 ms·
Transformation Priority Premise Applied
- Adrock 14y agoThe author walks through the iterative construction of the following Clojure code for figuring out how to make a specified amount out of coin denominations: (defn change-for [amount] (let [denominations [25 10 5 1] amounts (reductions #(rem %1 %2) amount denominations) coins (map #(int (/ %1 %2)) amounts denominations)] (mapcat #(take %1 (repeat %2)) coins denominations))) He does it while trying to minimize the "cost" of the code, which is defined in an interesting way for anyone who mostly writes imperative code.