Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
18
Task/Universal-Turing-machine/D/universal-turing-machine-2.d
Normal file
18
Task/Universal-Turing-machine/D/universal-turing-machine-2.d
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import std.stdio, std.typecons, std.algorithm, std.string, std.array;
|
||||
|
||||
void turing(Sy, St)(in St state, Sy[int] tape, in int pos,
|
||||
in Tuple!(Sy, int, St)[Sy][St] rules) {
|
||||
if (state.empty) return;
|
||||
const r = rules[state][tape[pos] = tape.get(pos, Sy.init)];
|
||||
writefln("%-(%s%)", tape.keys.sort()
|
||||
.map!(i => format(i == pos ? "(%s)" : " %s ", tape[i])));
|
||||
tape[pos] = r[0];
|
||||
turing(r[2], tape, pos + r[1], rules);
|
||||
}
|
||||
|
||||
void main() {
|
||||
turing("a", null, 0,
|
||||
["a": [0: tuple(1, 1, "b"), 1: tuple(1, -1, "c")],
|
||||
"b": [0: tuple(1, -1, "a"), 1: tuple(1, 1, "b")],
|
||||
"c": [0: tuple(1, -1, "b"), 1: tuple(1, 0, "")]]);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue