Flop Line of Chars?

Geoff Canyon gcanyon at inspiredlogic.com
Thu Dec 29 02:57:29 EST 2005


On Dec 28, 2005, at 10:41 PM, Scott Rossi wrote:

> In other words, change "ABCDEF" into "FEDCBA".

I don't know of a clever way to do this off the top of my head, but I  
do know that this:

   repeat for each char c in x
     put c before y
   end repeat

degrades _really_ badly as the size of x goes up. A 40k string on my  
1ghz powerbook takes several seconds.

On the other hand, this:

   repeat with i = 1 to length(x)
     put char -i of x after y
   end repeat

seems to degrade linearly, and a 40k string takes just 9 ticks.

This also degrades linearly, but takes five times as long as the  
above solution:

   put 0 into i
   repeat for each char c in x
     add 1 to i
     put c into z[i]
   end repeat
   repeat with i = i down to 1
     put z[i] after y
   end repeat

regards,

Geoff



More information about the Use-livecode mailing list