Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1997
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1997

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

Search the Archive

programing problem: list manipulation

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

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

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

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

 Xah, xah at best.com, http://www.best.com/~xah/
 "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