#43 Reverse Interleave
(fn f [arglist argnumber]
(->> arglist
(map-indexed vector)
(group-by #(mod (first %) argnumber))
(vals)
(map #(map last %))
)
)
;;-> Best answer : (apply map vector (partition n v))
#44 Rotate Sequence
(fn f [n v]
(let [newn (cond
(< n 0) (- (count v) (mod (- n) (count v)) )
(> n (count v) ) (mod n (count v))
:else n)]
(take (count v) (drop newn (flatten (repeat 2 v)) ) )
)
)
;;-> repeat 가 아니라 cycle이 있음.
#45 Intro to Iterate
'(1 4 7 10 13)
#46 Flipping out
(fn [fun]
(fn [x y] (fun y x) )
)
;;함수 자체를 리턴
#47 Contain Yourself
4
;; contain 의 경우 Key를 확인함.
#53 Longest Increasing Sub-Seq
(fn f [ve]
(let [pi (partition-by identity (map (fn [x y] (- x y)) ve (cons (first ve) ve)) )
count-ve (map #(if (= (first %) 1) (count %) -1) pi)
max-val (apply max count-ve)
start-pos (dec (first (keep-indexed (fn [idx v]
(if (= v max-val) idx)) count-ve)) ) ]
(take (inc max-val) (drop start-pos ve))
)
)
;;하드따리 풀어버리기
'프로그래밍 언어 노트 > Clojure' 카테고리의 다른 글
[Clojure] 4Clojure 6 (0) | 2019.10.30 |
---|---|
[Clojure] 4Clojure 5 (0) | 2019.09.14 |
[Clojure] 4Clojure Easy 3 (0) | 2019.07.13 |
[Clojure] 4Clojure Easy 2 (0) | 2019.07.10 |
[Clojure] 4Clojure Easy 1 (0) | 2019.07.10 |