Thursday, 15 March 2012

split - clojure: partition a seq based on a seq of values -


I would like to divide a CEC, based on one sec of values ​​

  (split -by-seq [3 5] [1 2 3 4 5 6] ((1 2 3) (4 5) (6))  

The first input is a seq number of the partition . The second input is a partition that I want to split. Therefore, the price of the first list will be divided into 3 (1 2 3) and the second will be divided (4 5) where 5 is the next division point.

The second example:

  (Partition-by-Sec [3] [2 3 4 5]) Results: ((2 3) (4 5)) -Dear-Seek [2 5] [2 3 5 6]) Results: ((2) (3 5) (6))  

Given: First Seak There is a subset of the second input sec.

<

   

I came up with this solution Lazy and fair (IMO) is straightforward. (Partial-seek [splitter call] (lazy-sek (when-to-go) (if-two [first splitters]]; First splitter to build seq first (s) (lieutenant # (& lt; =% Split-point (next s)); Constant lazy seq of division (opposition run (part-seq (rest splitters) (drop (counting run)))); If any splitter (list colonel

If divided digits are in all sequences:

  (part-seq [3] 5 8] [0 1 2 3 4 5 6 7 8 9]) ;; = & gt; (0 1 2 3) (4-5) (6 7 8) (9))  

If something split points < / Em> in the sequence Do not have

  (part-seq [3 5 8] [0 1 2 4 5 6 8 9]) ;; = & gt; splitters and order of division to some infinite scenes Example (with (0 1 2) (4 5) (6 8) (9))  

example.

(5 (Part-Sik ( Iterative (Partial + 3) 5) (Category));; = & gt; (1 2 3 4 5) (6 7 8) (910 11) (12 13 14) (15 16 17))

No comments:

Post a Comment