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