On 16-2-2013 19:55, bearophile wrote:
There is a way to make the D code faster: prepending a cell in left() is a slow 
operation:

void right() pure nothrow {
     this.position++;
     if (this.position == this.tape.length)
         this.tape ~= this.blank;
}

void left() pure nothrow {
     if (this.position == 0)
         this.tape = this.blank ~ this.tape;
     else
         this.position--;
}


If you want to make the code faster (useful for a larger Busy Beaver 
simulation), you keep two tapes as two dynamic arrays. One tape represents the 
items on the right of the origin and the other tape on the left of the origin. 
So the position becomes a signed integer and both left() and right() use a fast 
append operation.

Yes, that was your original suggestion, but I didn't quite understand it,
so I went with the Ruby solution. You would reverse the left array when
printing, is that correct?

Reply via email to