tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
17
Task/Catalan-numbers/Clojure/catalan-numbers.clj
Normal file
17
Task/Catalan-numbers/Clojure/catalan-numbers.clj
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
(def ! (memoize #(apply * (range 1 (inc %)))))
|
||||
|
||||
(defn catalan-numbers-direct []
|
||||
(map #(/ (! (* 2 %))
|
||||
(* (! (inc %)) (! %))) (range)))
|
||||
|
||||
(def catalan-numbers-recursive
|
||||
#(->> [1 1] ; [c0 n1]
|
||||
(iterate (fn [[c n]]
|
||||
[(* 2 (dec (* 2 n)) (/ (inc n)) c) (inc n)]) ,)
|
||||
(map first ,)))
|
||||
|
||||
user> (take 15 (catalan-numbers-direct))
|
||||
(1 1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440)
|
||||
|
||||
user> (take 15 (catalan-numbers-recursive))
|
||||
(1 1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440)
|
||||
Loading…
Add table
Add a link
Reference in a new issue