From c6aab50304f501b407beeecc765138a7b0998222 Mon Sep 17 00:00:00 2001 From: grammarware Date: Wed, 20 Jun 2012 14:39:19 +0200 Subject: [PATCH] duplicate --- examples/dup/README.txt | 13 ++++++++++++ examples/dup/copy2.ctur | 36 ++++++++++++++++++++++++++++++++ examples/dup/copy2.t_l2 | 46 +++++++++++++++++++++++++++++++++++++++++ examples/dup/dup.ctur | 20 ++++++++++++++++++ examples/dup/dup.t_l2 | 25 ++++++++++++++++++++++ 5 files changed, 140 insertions(+) create mode 100644 examples/dup/README.txt create mode 100644 examples/dup/copy2.ctur create mode 100644 examples/dup/copy2.t_l2 create mode 100644 examples/dup/dup.ctur create mode 100644 examples/dup/dup.t_l2 diff --git a/examples/dup/README.txt b/examples/dup/README.txt new file mode 100644 index 0000000..cd58df5 --- /dev/null +++ b/examples/dup/README.txt @@ -0,0 +1,13 @@ +There are two simple Turing Machine programs that duplicate a unary number. + +copy2 is the naïve implementation of concatenating two copy (cf.) programs. +It requires the first bit set to 0 in order to find it back. +(In the Rascal emulator you cannot move backwards farther than your starting position) + +e.g.: 0110… ⇒ 011011110… + +dup is a slightly less naïve but stupid implementation, which does what copy (cf.) does, +but adds two bits on each iteration. +It shows how Turing Machine programming does not have to be rocket science. + +-- Vadim Zaytsev, http://grammarware.net diff --git a/examples/dup/copy2.ctur b/examples/dup/copy2.ctur new file mode 100644 index 0000000..f4eaa0b --- /dev/null +++ b/examples/dup/copy2.ctur @@ -0,0 +1,36 @@ +MF +J036 +J034 +W0 +MF +J15 +MF +J17 +W1 +MB +J110 +MB +J112 +W1 +MF +J13 +MB +J117 +MF +J034 +W0 +MF +J122 +MF +J124 +W1 +MB +J127 +MB +J129 +W1 +MF +J120 +MF +J134 + diff --git a/examples/dup/copy2.t_l2 b/examples/dup/copy2.t_l2 new file mode 100644 index 0000000..3d9deb3 --- /dev/null +++ b/examples/dup/copy2.t_l2 @@ -0,0 +1,46 @@ +MF +J0 stop +L loop + J0 exit + W0 + REP 2 { + L skip + MF + J1 skip + } + W1 + REP 2 { + L back + MB + J1 back + } + W1 + MF + J1 loop +L back2 + MB + J1 back2 + MF +L loop2 + J0 exit + W0 + REP 2 { + L skip2 + MF + J1 skip2 + } + W1 + REP 2 { + L back3 + MB + J1 back3 + } + W1 + MF + J1 loop2 +L exit +L end + MF + J1 end +L stop + diff --git a/examples/dup/dup.ctur b/examples/dup/dup.ctur new file mode 100644 index 0000000..85556ff --- /dev/null +++ b/examples/dup/dup.ctur @@ -0,0 +1,20 @@ +J020 +J018 +W0 +MF +J14 +MF +J16 +W1 +MF +W1 +MB +J111 +MB +J113 +W1 +MF +J12 +MF +J118 + diff --git a/examples/dup/dup.t_l2 b/examples/dup/dup.t_l2 new file mode 100644 index 0000000..0f1f532 --- /dev/null +++ b/examples/dup/dup.t_l2 @@ -0,0 +1,25 @@ +J0 stop +L loop + J0 end + W0 + REP 2 { + L skip + MF + J1 skip + } + W1 + MF + W1 + REP 2 { + L back + MB + J1 back + } + W1 + MF + J1 loop +L end + MF + J1 end +L stop +