MathGroup Archive 1995

[Date Index] [Thread Index] [Author Index]

Search the Archive

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

  • Subject: [mg2632] Re: [mg2600] Re: [Q] {a,b,c}->{{a,b},{b,c}}
  • From: hay at (Allan Hayes)
  • Date: Thu, 30 Nov 1995 21:00:55 -0500
  • Approved:
  • Distribution: local
  • Newsgroups: wri.mathgroup
  • Organization: Wolfram Research, Inc.

In [mg2600] Re: [Q] {a,b,c}->{{a,b},{b,c}}
"Bart van der Zwet" <B.W.v.d.Zwet at>
gave a list of responses and timings (attached).

Here are two variants that are slightly quicker than the fastest he  
reports.The main improvement comes from using Thread instead of  

lst = Range[10^4];


   7.8 Second


   6.53333 Second


   6.5 Second

Allan Hayes
hay at

Begin forwarded message:

>From: "Bart van der Zwet" <B.W.v.d.Zwet at>
>Subject: [mg2600] Re: [Q] {a,b,c}->{{a,b},{b,c}}

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  
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.

2.64 Second

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

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

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

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

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


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

  • Prev by Date: Re: Re: What's in the " .mb" files????
  • Next by Date: Re: Bug in symbolic inversion of matrices
  • Previous by thread: Re: [Q] {a,b,c}->{{a,b},{b,c}}
  • Next by thread: X-FrontEnd crashes upon certain keystrokes