A little of coordination for Rosettacode

bearophile bearophileHUGS at lycos.com
Sat Feb 16 10:55:21 PST 2013


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.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list