Interleaving

2013-06-27 Thread Paul Meehan
Hi, Given a sequence (x1, y1, x2, y2, x3, y3,...) and another (z1, z2, z3, ...) I want to interleave such that I get a sequence (x1, y1, z1, x2, y2, z2, x3, y3, z3, ...) What's the most succinct way to achieve this? thanks Paul -- -- You received this message because you are subscribed to

Re: Interleaving

2013-06-27 Thread Paul Meehan
Hi Figured it out - Partition first sequence into two sequences then interleave the three sequences. Paul On Thursday, June 27, 2013 11:37:40 AM UTC+1, Paul Meehan wrote: Hi, Given a sequence (x1, y1, x2, y2, x3, y3,...) and another (z1, z2, z3, ...) I want to interleave such that I

Re: Interleaving

2013-06-27 Thread Meikel Brandmeyer (kotarak)
How about this? (interleave (take-nth 2 xys) (take-nth 2 (rest xys)) zs) Kind regards Meikel -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are

Re: Interleaving

2013-06-27 Thread Paul Meehan
given sequences xy and z (flatten (interleave (partition 1 2 xy) (partition 1 2 (rest xy)) z)) works.. On Thursday, June 27, 2013 11:37:40 AM UTC+1, Paul Meehan wrote: Hi, Given a sequence (x1, y1, x2, y2, x3, y3,...) and another (z1, z2, z3, ...) I want to interleave such that I get

Re: Interleaving

2013-06-27 Thread Alan Forrester
The solution (flatten (interleave (partition 1 2 xy) (partition 1 2 (rest xy)) z)) works provided that none of the elements of xy or z are seqs. For example if xy = [[1 3] [2 4] [3 7] [4 7]] and z= [[5] [6]] this solution produces (1 3 2 4 5 3 7 4 7 6). The other proposal (interleave (take-nth

Re: Interleaving

2013-06-27 Thread Kelker Ryan
Try this.  user (def xy [:x1 :y1 :x2 :y2 :x3 :y3])(as- xy _ (partition 2 _) (interleave _ [:z1 :z2 :z3]) (flatten _))#'user/xy(:x1 :y1 :z1 :x2 :y2 :z2 :x3 :y3 :z3)user  27.06.2013, 19:55, "Paul Meehan" paulchristophermee...@gmail.com:Hi,Given a sequence (x1, y1, x2, y2, x3, y3,...)and

Re: Interleaving

2013-06-27 Thread Yoshinori Kohyama
One more solution. user= (mapcat (fn [[x y] z] [x y z]) (partition 2 '(:x1 :y1 :x2 :y2 :x3 :y3)) '(:z1 :z2 :z3)) (:x1 :y1 :z1 :x2 :y2 :z2 :x3 :y3 :z3) Y. Kohyama -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email