RosettaCodeData/Task/Universal-Turing-machine/Deja-Vu/universal-turing-machine-1.djv
2014-01-17 05:34:36 +00:00

42 lines
700 B
Text

transitions(:
local :t {}
while /= ) dup:
set-to t swap & rot & rot rot &
t drop
take-from tape:
if tape:
pop-from tape
else:
:B
paste-together a h b:
push-to b h
while a:
push-to b pop-from a
b
universal-turing-machine transitions initial final tape:
local :tape-left []
local :state initial
local :head take-from tape
local :move { :stay @pass }
move!left:
push-to tape head
set :head take-from tape-left
move!right:
push-to tape-left head
set :head take-from tape
while /= state final:
if opt-get transitions & state head:
set :state &<>
set :head &<>
move!
else:
return paste-together tape-left head tape
paste-together tape-left head tape