so when you print the tape you trim the blanks away at both ends.

A wrong trimming code:


string toString() const {
    // Blank-stripped tape.
    const t2 = tape
               .find!(c => c != blank)()
               .retro()
               .find!(c => c != blank)()
               .retro();

    return format("...%(%)...", t2.empty ? [blank] : t2)
           ~ '\n'
           ~ format("%" ~ text(position + 4) ~ "s", "^")
           ~ '\n';
}


It gives:

Busy beaver machine (3-state, 2-symbol):
...0...
   ^
...1...
    ^


The second line should show the cell up to the head position:

Busy beaver machine (3-state, 2-symbol):
...0...
   ^
...10...
    ^


There are many ways to improve this program, like trimming away the blanks correctly, but I think the code is acceptable now:

http://rosettacode.org/wiki/Universal_Turing_machine#D

Bye,
bearophile

Reply via email to