MathGroup Archive 1997

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

Search the Archive

programing problem: list manipulation

  • To: mathgroup at
  • Subject: [mg7600] programing problem: list manipulation
  • From: Xah Lee <xah at>
  • Date: Thu, 19 Jun 1997 15:53:18 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

Another mma programing problem. I have two lists {1,2,3,4,5},
{b1,b2,b3,b4,b5} and I want the result to be
{{1,2,b2,b1},{2,3,b3,b2},{3,4,b4,b3},{4,5,b5,b4},{5,1,b1,b5}}. In this
particular problem, speed is my number one concern. The best solution I came
up is attached below. No doubt some of you will come up with faster

n=5; (*n will be around 5, not large*)
pts1=Range at n;
pts2=ToExpression/@(StringJoin["b",ToString at #]&/@pts1);

  Flatten[ Transpose[{ Transpose[{pts1,RotateLeft[pts1]}],
        Transpose[{RotateLeft[pts2],pts2}]}],2 ],4 ]

 Xah, xah at,
 "I'm a programer, you're a programmer."

  • Prev by Date: Mathematica 1.0?
  • Next by Date: (Mac) Missing font outline file
  • Previous by thread: Mathematica 1.0?
  • Next by thread: (Mac) Missing font outline file