A little of coordination for Rosettacode
bearophile
bearophileHUGS at lycos.com
Sun Feb 17 14:21:45 PST 2013
> 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
More information about the Digitalmars-d-learn
mailing list