September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,20 @@
var [const] D=Dictionary; // short cut
// blank symbol and terminating state(s) are Void
var Lt=-1, Sy=0, Rt=1; // Left, Stay, Right
fcn printTape(tape,pos){
tape.keys.apply("toInt").sort()
.pump(String,'wrap(i){ ((pos==i) and "(%s)" or " %s ").fmt(tape[i]) })
.println();
}
fcn turing(state,[D]tape,[Int]pos,[D]rules,verbose=True,n=0){
if(not state){
print("%d steps. Length %d. Tape: ".fmt(n,tape.len()));
printTape(tape,Void);
return(tape);
}
r:=rules[state][tape[pos] = tape.find(pos)];
if(verbose) printTape(tape,pos);
tape[pos]=r[0];
return(self.fcn(r[2],tape,pos+r[1],rules,verbose,n+1));
}

View file

@ -0,0 +1,25 @@
println("Simple incrementer");
turing("q0",D(0,Rt, 1,Rt, 2,Rt),0, // Incrementer
D("q0",D(1,T(1,Rt,"q0"), Void,T(1,Sy,Void)) ) );
println("\nThree-state busy beaver");
turing("a",D(),0, // Three-state busy beaver
SD("a",D(Void,T(1,Rt,"b"), 1,T(1,Lt,"c")),
"b",D(Void,T(1,Lt,"a"), 1,T(1,Rt,"b")),
"c",D(Void,T(1,Lt,"b"), 1,T(1,Sy,Void)) ) );
println("\nSort");
turing("A",D(T(2,2,2,1,2,2,1,2,1,2,1,2,1,2).enumerate()),0,
SD("A",D(1,T(1,Rt,"A"), 2,T(3,Rt,"B"), Void,T(Void,Lt,"E")),
"B",D(1,T(1,Rt,"B"), 2,T(2,Rt,"B"), Void,T(Void,Lt,"C")),
"C",D(1,T(2,Lt,"D"), 2,T(2,Lt,"C"), 3, T(2, Lt,"E")),
"D",D(1,T(1,Lt,"D"), 2,T(2,Lt,"D"), 3, T(1, Rt,"A")),
"E",D(1,T(1,Lt,"E"), Void,T(Void,Rt,Void)) ) ,False);
println("\nFive-state busy beaver");
turing("A",D(),0,
SD("A",D(Void,T(1,Rt,"B"), 1,T(1, Lt,"C")),
"B",D(Void,T(1,Rt,"C"), 1,T(1, Rt,"B")),
"C",D(Void,T(1,Rt,"D"), 1,T(Void,Lt,"E")),
"D",D(Void,T(1,Lt,"A"), 1,T(1, Lt,"D")),
"E",D(Void,T(1,Sy,Void), 1,T(Void,Lt,"A")) ) ,False);