#30 Compress a Sequence
(fn f [v]
(map first (partition-by identity v) )
)
#31 Pack a Sequence
(fn f [v]
(partition-by identity v)
)
;;머지 파티션-바이 를 쓰는게 아닌가..
#33 Replicate a Sequence
(fn f [vec repeat_number]
(mapcat #(repeat repeat_number %) vec)
)
#34 Implement range
(defn f [s e]
(take (- e s)
( (fn my-number-seq [s]
(lazy-seq (cons s (my-number-seq (inc s)) ))
) s )))
#39 Interleave Two Seqs
(fn f [vec1 vec2]
(mapcat list vec1 vec2)
)
#40 Interpose a Seq
(fn f [i vec2]
(pop (vec (mapcat list vec2 (repeat i)) ) )
)
#41 Drop Every Nth item
(fn f [v n]
(keep-indexed #(if (not= 0 (mod (inc %1) n)) %2) v )
)
#42 Factorial Fun
(fn f [n]
( (fn fac [c n v]
(if (= c n) v
(recur (inc c) n (* v c)))
) 1 (inc n) 1
)
)
;;재귀적
(fn f [n]
(apply * (range 1 (inc n)) )
)
;;스트림 사용
;;왜 갑자기 펙토리얼?
#28 flatten a sequence //못풀었던거
(fn [x] (filter (complement coll?) (tree-seq coll? seq x) ))
'프로그래밍 언어 노트 > Clojure' 카테고리의 다른 글
[Clojure] 4Clojure 5 (0) | 2019.09.14 |
---|---|
[Clojure] 4Clojure 4 (0) | 2019.07.21 |
[Clojure] 4Clojure Easy 2 (0) | 2019.07.10 |
[Clojure] 4Clojure Easy 1 (0) | 2019.07.10 |
[Clojure] 클로저 디자인패턴 (0) | 2019.06.28 |