Universal Turing machine: Difference between revisions
Content deleted Content added
Added solution for EDSAC. |
mNo edit summary |
||
Line 593: | Line 593: | ||
111111 STOP |
111111 STOP |
||
^</pre> |
^</pre> |
||
=={{header|Amazing Hopper}}== |
|||
Implementation of a Universal Turing Machine: |
|||
<lang Amazing Hopper> |
|||
#include <hopper.h> |
|||
#proto UniversalTuringMachine(_X_) |
|||
main: |
|||
.ctrlc |
|||
stbegin=0,stEnd=0,state=0,ptr=0 |
|||
tape=0,states=0,rules=0,long=0 |
|||
file="turing/prg01.tm" |
|||
// load program, rules & states: |
|||
jsub(load Archive) |
|||
// RUN Universal Turing Machine program: |
|||
i=1 |
|||
__TURING_RUN__: |
|||
_Universal Turing Machine ([i,1:end]get(rules)) |
|||
++i,{long,i}gt? do{ i=1 } |
|||
jt(__TURING_RUN__) |
|||
println |
|||
exit(0) |
|||
.locals |
|||
printTape: |
|||
#hl{ |
|||
print(tape[1:(ptr-1)],"\R",tape[ptr],"\OFF",tape[(ptr+1):end],"\n") |
|||
sleep(1) |
|||
} |
|||
up(1) |
|||
clear mark |
|||
back |
|||
Universal Turing Machine(rules) |
|||
cont=1 |
|||
clear mark |
|||
#hl{ |
|||
if( rules[1] == state ) |
|||
if( tape[ptr] == rules[2] ) |
|||
tape[ptr] = rules[3] |
|||
ptr += rules[4] |
|||
state = rules[5] |
|||
if(state == stEnd) |
|||
cont=0 |
|||
endif |
|||
} |
|||
jsub(print Tape) |
|||
#hl{ |
|||
endif |
|||
endif |
|||
}, {cont} |
|||
back |
|||
load Archive: |
|||
{","}tok sep |
|||
{file} stats file |
|||
[1,1:end],{file},!(5),load, mov(tape) |
|||
[2,1:3], !(5),load, mov(states) |
|||
[3:end,1:5], load, mov(rules) |
|||
clear mark |
|||
[1:end,4]get(rules),colMoving=0, mov(colMoving) |
|||
{"1","RIGHT",colMoving} transform, mov(colMoving) |
|||
{"-1","LEFT",colMoving} transform, mov(colMoving) |
|||
{"0","STAY",colMoving} transform, xtonum, put(rules) |
|||
clear mark |
|||
{0}reshape(tape) |
|||
#hl{ |
|||
stbegin=states[1,1] |
|||
stEnd=states[1,2] |
|||
ptr=states[1,3] |
|||
state=stbegin |
|||
} |
|||
data rules=0, size(rules), mov(datarules), [2]get(data rules), mov(long) |
|||
{""}tok sep |
|||
back |
|||
</lang> |
|||
Program PRG01.TM: |
|||
row 1: tape. |
|||
row 2: initial state, halt state, and initial pointer position |
|||
row 3 to end, columns 1 to 5: rules. |
|||
<pre> |
|||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 |
|||
a,halt,5 |
|||
a,0,1,RIGHT,b |
|||
a,1,1,LEFT,c |
|||
b,0,1,LEFT,a |
|||
b,1,1,RIGHT,b |
|||
c,0,1,LEFT,b |
|||
c,1,1,STAY,halt |
|||
</pre> |
|||
{{out}} |
|||
<pre> |
|||
0111111000000000000000000 |
|||
</pre> |
|||
=={{header|APL}}== |
=={{header|APL}}== |
||
{{works with|Dyalog APL}} |
{{works with|Dyalog APL}} |