-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtm.AnBn-1
104 lines (72 loc) · 1.47 KB
/
tm.AnBn-1
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#n
# Accepts tape: a{n}b{n}
# Example: echo 'aabb' | sed -rf tm.AnBn-1
# This source code is released under MIT License
# Copyright (c) 2016 Peter Cerman (https://github.com/pcerman)
/^>/ !s/^/>/
/#$/ !s/$/#/
#---------------------------------------------------------------------
:S0
#---------------------------------------------------------------------
p
s/>a/#>/
t S1
s/>#/#>/
t S4
b error
#---------------------------------------------------------------------
:S1
#---------------------------------------------------------------------
p
s/>a/a>/
t S1
s/>b/b>/
t S1
s/(.)>#/>\1#/
t S2
b error
#---------------------------------------------------------------------
:S2
#---------------------------------------------------------------------
p
s/(.)>b/>\1#/
t S3
b error
#---------------------------------------------------------------------
:S3
#---------------------------------------------------------------------
p
s/(.)>([ab])/>\1\2/
t S3
s/>#/#>/
t S0
b error
#---------------------------------------------------------------------
:S4
#---------------------------------------------------------------------
p
s/>#/#>/
t S5
/>$/ b halt
b error
#---------------------------------------------------------------------
:S5
#---------------------------------------------------------------------
p
s/>#/#>/
t halt
/>$/ b halt
b error
#---------------------------------------------------------------------
:error
i \
\
ERROR - invalid tape
p
q 1
:halt
i\
\
accepted
p
q 0