summaryrefslogtreecommitdiff
path: root/src/toys/turing/js/samples.js
blob: 0998ee4a6d0173e1383589aaa5eabb2f59e03afe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Example programs with initial tape states
export const EXAMPLE_PROGRAMS = [
  {
    name: "Replace two B's",
    code: `#start q0
#accept acc
#reject rej

q0 B 1 R q1
q1 1 1 R q1
q1 B 1 R acc`,
    initialTape: ""
  },
  {
    name: "Binary equality checker",
    code: `// https://stackoverflow.com/questions/59045832

#start q0
#accept acc
#reject rej

q0 0 X R q1
q0 1 X R q2
q0 = = R q7
q1 0 0 R q1
q1 1 1 R q1
q1 = = R q3
q2 0 0 R q2
q2 1 1 R q2
q2 = = R q4
q3 X X R q3
q3 0 X L q5
q3 1 1 L rej
q3 B B L rej
q4 X X R q4
q4 0 0 L rej
q4 B B L rej
q4 1 X L q5
q5 X X L q5
q5 = = L q6
q6 0 0 L q6
q6 1 1 L q6
q6 X X R q0
q7 X X R q7
q7 B B L q8
q7 0 0 L rej
q7 1 1 L rej
q8 X X L q8
q8 0 0 L q8
q8 1 1 L q8
q8 = = L acc`,
    initialTape: "1011=1011"
  },
  {
    name: "Binary addition",
    code: `// https://stackoverflow.com/questions/59045832

#start q0
#accept acc
#reject rej

q0 B B R q0
q0 0 0 R q0
q0 1 1 R q0
q0 + + R q1
q1 0 0 R q1
q1 1 1 R q1
q1 B B L q2
q2 0 1 L q2
q2 1 0 L q3
q2 + + R q5
q3 0 0 L q3
q3 1 1 L q3
q3 + + L q4
q4 0 1 R q0
q4 1 0 L q4
q4 B 1 R q0
q5 1 B R q5
q5 B B R q6
q6 B B L q6
q6 + B L q7
q7 0 0 L q7
q7 1 1 L q7
q7 B B R acc
`,
    initialTape: "101+110"
  }
];