Re: [Q] {a,b,c}->{{a,b},{b,c}}

• To: mathgroup at smc.vnet.net
• Subject: [mg2600] Re: [Q] {a,b,c}->{{a,b},{b,c}}
• From: "Bart van der Zwet" <B.W.v.d.Zwet at stud.tue.nl>
• Date: Mon, 27 Nov 1995 21:34:21 -0500

```Hello Mma-users,

I while ago I posted a question here.
I wanted to know how I could make {{a,b},{b,c}} out of {a,b,c} for instance,
but then for any list.
I received a number of different solutions that I shall mention in this
mail. I've let them all solve the problem for the list : Range[10^4] and
I include the timing to each solution.

1:
Partition[list,2,1]
2.64 Second

2:
Map[ Module[ {qux = absolutelyNothing},
(If[ qux === absolutelyNothing,
qux = #; Sequence @@ {},
{qux, qux = #} ])& ], list ]
9.51 Second

3:
Transpose[ { Drop[ list, -1 ], Drop[ list, 1 ] } ]
1.81 Second

4:
r[ {x__} ] := Map[ Pattern[ #, Blank[] ]&, {x} ] ->
Table[ { {x}[[i]], {x}[[i+1]] }, {i, 1, Length[ {x} ] - 1 } ]
x /. r[x]
33.94 Second

P.S.
Not all responses are included, some didn't do exactly what I wanted or I
couldn't get the answer with them. Some minor changes have been made in a
solution.

P.P.S.
Thank you all for replying to my question, it's been of great help.

Yours,

Bart van der Zwet
Student Mathematics
Eindhoven University of Technology
The Netherlands
e-mail : B.W.v.d.Zwet at stud.tue.nl

```