Hacker News new | past | comments | ask | show | jobs | submit login
Transformation Priority Premise Applied (8thlight.com)
1 point by Adrock on Nov 18, 2012 | hide | past | favorite | 1 comment



The 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.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: