簡単な硬貨問題 from IT速報3
まあこれもありかも。
(def coins [500 100 50 10 5 1]) (defn f [[remainder & count-list] coin] (concat ((juxt rem quot) remainder coin) count-list)) (defn coin-count2 [n] (->> coins (reduce f (list n)) next reverse))
reduceの戻り値を、これまでの商のリストの先頭に余を加えたものにすると比較的シンプル。
ただ、これだとリストの先頭とそれ以外で意味が違ってくるので、そこはちょっと悲しい。
しかしdestructuringは便利である。