Arantium Maestum

プログラミング、囲碁、読書の話題

2016-05-06から1日間の記事一覧

簡単な硬貨問題 from IT速報2

前回 ふと気づいたのだが、この問題ってreduceじゃなくてreductionsで書けば、「fの中でvectorを作成してそれを戻り値のvectorに入れて・・・」というvector入れ子状態を避けられる。 (def coins [500 100 50 10 5 1]) (defn f [[last-count remain] coin] (…

Clojureでマージソート2

とりあえずiterate版も貼っておく。 (defn merge ([col] col) ([[head1 & rest1 :as col1] [head2 & rest2 :as col2]] (cond (some empty? [col1 col2]) (concat col1 col2) (< head1 head2) (lazy-seq (cons head1 (merge rest1 col2))) :else (lazy-seq (c…