aboutsummaryrefslogtreecommitdiff
path: root/exercises.icl
diff options
context:
space:
mode:
Diffstat (limited to 'exercises.icl')
-rw-r--r--exercises.icl45
1 files changed, 44 insertions, 1 deletions
diff --git a/exercises.icl b/exercises.icl
index f0f583c..0fe8f31 100644
--- a/exercises.icl
+++ b/exercises.icl
@@ -6,7 +6,7 @@ import TuringMachines
Start :: *World -> *World
Start w
# (io,w) = stdio w
-# m = initTuringMachine ex_9_4 tape_9_4
+# m = initTuringMachine ex_9_3_b tape_9_3_b
# io = fwrites (toString m +++ "\n") io
# io = loop m io
# (ok,w) = fclose io w
@@ -19,6 +19,20 @@ where
| m.running == Running = loop m f
| otherwise = f
+tape_9_2_b = [Just c \\ c <- fromString "abab"]
+ex_9_2_b :: TuringMachine Char
+ex_9_2_b = { alphabet = ['a', 'b'],
+ inputs = ['a', 'b'],
+ transition = f }
+where
+ f :: Int (Maybe Char) -> TuringMachineMove Char
+ f 0 Nothing = Step 1 Nothing Right
+ f 1 (Just 'c') = Step 2 (Just 'c') Left
+ f 1 c = Step 1 c Right
+ f 2 (Just 'a') = Step 2 (Just 'a') Left
+ f 2 (Just 'b') = Step 2 (Just 'b') Left
+ f _ _ = Halt
+
tape_9_3_b = [Just c \\ c <- fromString "abbaba"]
ex_9_3_b :: TuringMachine Char
ex_9_3_b = { alphabet = ['a', 'b', 'X', 'Y'],
@@ -117,3 +131,32 @@ where
f _ _ = Halt
+tape_9_5_c = [Just c \\ c <- fromString "abbabbabaa"]
+ex_9_5_c :: TuringMachine Char
+ex_9_5_c = { alphabet = ['a', 'b'],
+ inputs = ['a', 'b'],
+ transition = f }
+where
+ f :: Int (Maybe Char) -> TuringMachineMove Char
+ f 0 Nothing = Step 1 Nothing Right
+
+ f 1 (Just 'a') = Step 2 (Just 'X') Left
+ f 1 (Just c) = Step 1 (Just c) Right
+ f 1 Nothing = Step 5 Nothing Left
+
+ f 2 (Just 'b') = Step 2 (Just 'b') Left
+ f 2 (Just 'X') = Step 2 (Just 'X') Left
+ f 2 Nothing = Step 3 Nothing Right
+
+ f 3 (Just 'X') = Step 3 (Just 'X') Right
+ f 3 (Just 'a') = Step 3 (Just 'a') Right
+ f 3 (Just 'b') = Step 4 (Just 'X') Right
+
+ f 4 (Just c) = Step 4 (Just c) Left
+ f 4 Nothing = Step 1 Nothing Right
+
+ f 5 (Just 'X') = Step 5 (Just 'X') Left
+ f 5 Nothing = Step 6 Nothing Right
+
+ f _ _ = Halt
+