@turing-machine-js/library-binary-numbers 2.0.0-alpha.0 → 2.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +17 -0
- package/dist/index.js +227 -0
- package/package.json +3 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { State, TapeBlock } from '@turing-machine-js/machine/src';
|
|
2
|
+
declare function getTapeBlock(): TapeBlock;
|
|
3
|
+
declare const _default: {
|
|
4
|
+
getTapeBlock: typeof getTapeBlock;
|
|
5
|
+
states: {
|
|
6
|
+
goToNumber: State;
|
|
7
|
+
goToNextNumber: State;
|
|
8
|
+
goToPreviousNumber: State;
|
|
9
|
+
deleteNumber: State;
|
|
10
|
+
goToNumbersStart: State;
|
|
11
|
+
invertNumber: State;
|
|
12
|
+
normalizeNumber: State;
|
|
13
|
+
plusOne: State;
|
|
14
|
+
minusOne: State;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export default _default;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { Alphabet, haltState, ifOtherSymbol, movements, State, symbolCommands, TapeBlock, } from '@turing-machine-js/machine/src';
|
|
2
|
+
const alphabet = new Alphabet(' ^$01'.split(''));
|
|
3
|
+
const tapeBlock = TapeBlock.fromAlphabets([alphabet]);
|
|
4
|
+
const { symbol } = tapeBlock;
|
|
5
|
+
const goToNumber = new State({
|
|
6
|
+
[symbol('$')]: {
|
|
7
|
+
nextState: haltState,
|
|
8
|
+
},
|
|
9
|
+
[ifOtherSymbol]: {
|
|
10
|
+
command: {
|
|
11
|
+
movement: movements.right,
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
}, 'goToNumber');
|
|
15
|
+
const goToNextNumber = new State({
|
|
16
|
+
[ifOtherSymbol]: {
|
|
17
|
+
command: {
|
|
18
|
+
movement: movements.right,
|
|
19
|
+
},
|
|
20
|
+
nextState: goToNumber,
|
|
21
|
+
},
|
|
22
|
+
}, 'goToNextNumber');
|
|
23
|
+
const goToPreviousNumberInternal = new State({
|
|
24
|
+
[symbol('$')]: {
|
|
25
|
+
nextState: haltState,
|
|
26
|
+
},
|
|
27
|
+
[ifOtherSymbol]: {
|
|
28
|
+
command: {
|
|
29
|
+
movement: movements.left,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
}, 'goToPreviousNumberInternal');
|
|
33
|
+
const goToPreviousNumber = new State({
|
|
34
|
+
[ifOtherSymbol]: {
|
|
35
|
+
command: {
|
|
36
|
+
movement: movements.left,
|
|
37
|
+
},
|
|
38
|
+
nextState: goToPreviousNumberInternal,
|
|
39
|
+
},
|
|
40
|
+
}, 'goToPreviousNumber');
|
|
41
|
+
const goToNumbersStart = new State({
|
|
42
|
+
[symbol('^')]: {
|
|
43
|
+
nextState: haltState,
|
|
44
|
+
},
|
|
45
|
+
[ifOtherSymbol]: {
|
|
46
|
+
command: {
|
|
47
|
+
movement: movements.left,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
}, 'goToNumberStart');
|
|
51
|
+
const deleteNumberInternal = new State({
|
|
52
|
+
[symbol('$')]: {
|
|
53
|
+
command: {
|
|
54
|
+
symbol: symbolCommands.erase,
|
|
55
|
+
},
|
|
56
|
+
nextState: haltState,
|
|
57
|
+
},
|
|
58
|
+
[ifOtherSymbol]: {
|
|
59
|
+
command: {
|
|
60
|
+
symbol: symbolCommands.erase,
|
|
61
|
+
movement: movements.right,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
}, 'deleteNumberInternal');
|
|
65
|
+
const deleteNumber = new State({
|
|
66
|
+
[symbol('^10$')]: {
|
|
67
|
+
nextState: goToNumbersStart.withOverrodeHaltState(deleteNumberInternal),
|
|
68
|
+
},
|
|
69
|
+
[ifOtherSymbol]: {
|
|
70
|
+
nextState: haltState,
|
|
71
|
+
},
|
|
72
|
+
}, 'deleteNumber');
|
|
73
|
+
const invertNumberGoToNumberWithInversion = new State({
|
|
74
|
+
[symbol('^')]: {
|
|
75
|
+
command: {
|
|
76
|
+
movement: movements.right,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
[symbol('1')]: {
|
|
80
|
+
command: {
|
|
81
|
+
symbol: '0',
|
|
82
|
+
movement: movements.right,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
[symbol('0')]: {
|
|
86
|
+
command: {
|
|
87
|
+
symbol: '1',
|
|
88
|
+
movement: movements.right,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
[symbol('$')]: {
|
|
92
|
+
nextState: haltState,
|
|
93
|
+
},
|
|
94
|
+
}, 'invertNumberGoToNumberWithInversion');
|
|
95
|
+
const invertNumber = new State({
|
|
96
|
+
[symbol('^10$')]: {
|
|
97
|
+
nextState: goToNumbersStart.withOverrodeHaltState(invertNumberGoToNumberWithInversion),
|
|
98
|
+
},
|
|
99
|
+
[ifOtherSymbol]: {
|
|
100
|
+
nextState: haltState,
|
|
101
|
+
},
|
|
102
|
+
}, 'invertNumber');
|
|
103
|
+
const normalizeNumberPutNewStartSymbol = new State({
|
|
104
|
+
[symbol(alphabet.blankSymbol)]: {
|
|
105
|
+
command: {
|
|
106
|
+
symbol: '^',
|
|
107
|
+
},
|
|
108
|
+
nextState: goToNumber,
|
|
109
|
+
},
|
|
110
|
+
}, 'normalizeNumberPutNewStartSymbol');
|
|
111
|
+
const normalizeNumberMoveNumberStart = new State({
|
|
112
|
+
[symbol('^0')]: {
|
|
113
|
+
command: {
|
|
114
|
+
symbol: symbolCommands.erase,
|
|
115
|
+
movement: movements.right,
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
[symbol('1$')]: {
|
|
119
|
+
command: {
|
|
120
|
+
movement: movements.left,
|
|
121
|
+
},
|
|
122
|
+
nextState: normalizeNumberPutNewStartSymbol,
|
|
123
|
+
},
|
|
124
|
+
}, 'normalizeNumberMoveNumberStart');
|
|
125
|
+
const normalizeNumber = new State({
|
|
126
|
+
[symbol('^10$')]: {
|
|
127
|
+
nextState: goToNumbersStart.withOverrodeHaltState(normalizeNumberMoveNumberStart),
|
|
128
|
+
},
|
|
129
|
+
[ifOtherSymbol]: {
|
|
130
|
+
nextState: haltState,
|
|
131
|
+
},
|
|
132
|
+
}, 'normalizeNumber');
|
|
133
|
+
const plusOneFillZeros = new State({
|
|
134
|
+
[symbol('1')]: {
|
|
135
|
+
command: {
|
|
136
|
+
symbol: '0',
|
|
137
|
+
movement: movements.right,
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
[symbol('$')]: {
|
|
141
|
+
nextState: haltState,
|
|
142
|
+
},
|
|
143
|
+
}, 'plusOneFillZeros');
|
|
144
|
+
const plusOneAddNumberStart = new State({
|
|
145
|
+
[symbol(alphabet.blankSymbol)]: {
|
|
146
|
+
command: {
|
|
147
|
+
symbol: '^',
|
|
148
|
+
movement: movements.right,
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
[symbol('1')]: {
|
|
152
|
+
command: {
|
|
153
|
+
movement: movements.right,
|
|
154
|
+
},
|
|
155
|
+
nextState: plusOneFillZeros,
|
|
156
|
+
},
|
|
157
|
+
}, 'plusOneAddNumberStart');
|
|
158
|
+
const plusOneCaryOne = new State({
|
|
159
|
+
[symbol('0')]: {
|
|
160
|
+
command: {
|
|
161
|
+
symbol: '1',
|
|
162
|
+
movement: movements.right,
|
|
163
|
+
},
|
|
164
|
+
nextState: plusOneFillZeros,
|
|
165
|
+
},
|
|
166
|
+
[symbol('1')]: {
|
|
167
|
+
command: {
|
|
168
|
+
movement: movements.left,
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
[symbol('^')]: {
|
|
172
|
+
command: {
|
|
173
|
+
symbol: '1',
|
|
174
|
+
movement: movements.left,
|
|
175
|
+
},
|
|
176
|
+
nextState: plusOneAddNumberStart,
|
|
177
|
+
},
|
|
178
|
+
}, 'plusOneCaryOne');
|
|
179
|
+
const plusOne = new State({
|
|
180
|
+
[symbol('^10')]: {
|
|
181
|
+
command: {
|
|
182
|
+
movement: movements.right,
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
[symbol('$')]: {
|
|
186
|
+
command: {
|
|
187
|
+
movement: movements.left,
|
|
188
|
+
},
|
|
189
|
+
nextState: plusOneCaryOne,
|
|
190
|
+
},
|
|
191
|
+
[ifOtherSymbol]: {
|
|
192
|
+
nextState: haltState,
|
|
193
|
+
},
|
|
194
|
+
}, 'plusOne');
|
|
195
|
+
const minusOne = new State({
|
|
196
|
+
[symbol('^10')]: {
|
|
197
|
+
command: {
|
|
198
|
+
movement: movements.right,
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
[symbol('$')]: {
|
|
202
|
+
nextState: invertNumber
|
|
203
|
+
.withOverrodeHaltState(plusOne
|
|
204
|
+
.withOverrodeHaltState(invertNumber
|
|
205
|
+
.withOverrodeHaltState(normalizeNumber))),
|
|
206
|
+
},
|
|
207
|
+
[ifOtherSymbol]: {
|
|
208
|
+
nextState: haltState,
|
|
209
|
+
},
|
|
210
|
+
}, 'minusOne');
|
|
211
|
+
function getTapeBlock() {
|
|
212
|
+
return tapeBlock.clone();
|
|
213
|
+
}
|
|
214
|
+
export default {
|
|
215
|
+
getTapeBlock,
|
|
216
|
+
states: {
|
|
217
|
+
goToNumber,
|
|
218
|
+
goToNextNumber,
|
|
219
|
+
goToPreviousNumber,
|
|
220
|
+
deleteNumber,
|
|
221
|
+
goToNumbersStart,
|
|
222
|
+
invertNumber,
|
|
223
|
+
normalizeNumber,
|
|
224
|
+
plusOne,
|
|
225
|
+
minusOne,
|
|
226
|
+
},
|
|
227
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turing-machine-js/library-binary-numbers",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.1",
|
|
4
4
|
"description": "A standard library for working with binary numbers",
|
|
5
5
|
"author": "Ruslan Gilmullin <mellonis14@gmain.com>",
|
|
6
6
|
"homepage": "https://github.com/mellonis/turing-machine-js#readme",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"numbers"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@turing-machine-js/machine": "^2.0.0-alpha.
|
|
27
|
+
"@turing-machine-js/machine": "^2.0.0-alpha.1"
|
|
28
28
|
},
|
|
29
29
|
"module": "index.js",
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "2eb49e091614e3c65f95bbd7626943263fb4d1b3"
|
|
31
31
|
}
|