@turing-machine-js/library-binary-numbers 1.0.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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @turing-machine-js/library-binary-numbers
2
2
 
3
- [![Build Status](https://travis-ci.com/mellonis/turing-machine-js.svg?branch=next)](https://travis-ci.com/mellonis/turing-machine-js)
4
- ![npm (tag)](https://img.shields.io/npm/v/@turing-machine-js/library-binary-numbers/next)
3
+ [![build](https://github.com/mellonis/turing-machine-js/actions/workflows/main.yml/badge.svg)](https://github.com/mellonis/turing-machine-js/actions/workflows/main.yml)
4
+ ![npm (tag)](https://img.shields.io/npm/v/@turing-machine-js/library-binary-numbers)
5
5
 
6
6
  A library for the turing-machine-js.
7
7
 
@@ -13,12 +13,6 @@ Using npm:
13
13
  npm install @turing-machine-js/library-binary-numbers
14
14
  ```
15
15
 
16
- or using yarn:
17
-
18
- ```sh
19
- yarn add @turing-machine-js/library-binary-numbers
20
- ```
21
-
22
16
  ## A concept
23
17
 
24
18
  Binary numbers are represented as a sequence of symbols `0` and `1`.
@@ -51,6 +45,6 @@ If you want to use states which were described earlier, you must use a tape bloc
51
45
 
52
46
  ## Links
53
47
 
54
- - The information about `TapeBlock` and `State` classes is [here](https://github.com/mellonis/turing-machine-js/tree/next/packages/machine)
48
+ - The information about `TapeBlock` and `State` classes is [here](https://github.com/mellonis/turing-machine-js/tree/master/packages/machine)
55
49
  - [Turing Machine](https://en.wikipedia.org/wiki/Turing_machine) on the Wikipedia
56
50
 
@@ -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": "1.0.0",
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,13 +24,8 @@
24
24
  "numbers"
25
25
  ],
26
26
  "dependencies": {
27
- "@turing-machine-js/machine": "^1.0.0"
27
+ "@turing-machine-js/machine": "^2.0.0-alpha.1"
28
28
  },
29
- "main": "dist/index.cjs.js",
30
- "module": "dist/index.es.js",
31
- "scripts": {
32
- "build": "rollup -c ../../rollup.config.mjs",
33
- "test": "jest --colors"
34
- },
35
- "gitHead": "2a9ef21893e125282272aba41a747c7b638400db"
29
+ "module": "index.js",
30
+ "gitHead": "2eb49e091614e3c65f95bbd7626943263fb4d1b3"
36
31
  }
package/dist/index.cjs.js DELETED
@@ -1 +0,0 @@
1
- "use strict";var e=require("@turing-machine-js/machine");const t=new e.Alphabet({symbolList:" ^$01".split("")}),m=new e.TapeBlock({alphabetList:[t]}),{symbol:o}=m,n=new e.State({[o("$")]:{nextState:e.haltState},[e.ifOtherSymbol]:{command:{movement:e.movements.right}}},"goToNumber"),a=new e.State({[e.ifOtherSymbol]:{command:{movement:e.movements.right},nextState:n}},"goToNextNumber"),r=new e.State({[o("$")]:{nextState:e.haltState},[e.ifOtherSymbol]:{command:{movement:e.movements.left}}},"goToPreviousNumberTrue"),l=new e.State({[e.ifOtherSymbol]:{command:{movement:e.movements.left},nextState:r}},"goToPreviousNumber"),S=new e.State({[o("^")]:{nextState:e.haltState},[e.ifOtherSymbol]:{command:{movement:e.movements.left}}},"goToNumberStart"),s=new e.State({[o("$")]:{command:{symbol:e.symbolCommands.erase},nextState:e.haltState},[e.ifOtherSymbol]:{command:{symbol:e.symbolCommands.erase,movement:e.movements.right}}},"deleteNumberTrue"),v=new e.State({[o("^10$")]:{nextState:S.withOverrodeHaltState(s)},[e.ifOtherSymbol]:{nextState:e.haltState}},"deleteNumber"),b=new e.State({[o("^")]:{command:{movement:e.movements.right}},[o("1")]:{command:{symbol:"0",movement:e.movements.right}},[o("0")]:{command:{symbol:"1",movement:e.movements.right}},[o("$")]:{nextState:e.haltState}},"invertNumberGoToNumberWithInversion"),i=new e.State({[o("^10$")]:{nextState:S.withOverrodeHaltState(b)},[e.ifOtherSymbol]:{nextState:e.haltState}},"invertNumber"),h=new e.State({[o(t.blankSymbol)]:{command:{symbol:"^"},nextState:n}},"normalizeNumberPutNewStartSymbol"),u=new e.State({[o("^0")]:{command:{symbol:e.symbolCommands.erase,movement:e.movements.right}},[o("1$")]:{command:{movement:e.movements.left},nextState:h}},"normalizeNumberMoveNumberStart"),d=new e.State({[o("^10$")]:{nextState:S.withOverrodeHaltState(u)},[e.ifOtherSymbol]:{nextState:e.haltState}},"normalizeNumber"),c=new e.State({[o("1")]:{command:{symbol:"0",movement:e.movements.right}},[o("$")]:{nextState:e.haltState}},"plusOneFillZeros"),y=new e.State({[o(t.blankSymbol)]:{command:{symbol:"^",movement:e.movements.right}},[o("1")]:{command:{movement:e.movements.right},nextState:c}},"plusOneAddNumberStart"),w=new e.State({[o("0")]:{command:{symbol:"1",movement:e.movements.right},nextState:c},[o("1")]:{command:{movement:e.movements.left}},[o("^")]:{command:{symbol:"1",movement:e.movements.left},nextState:y}},"plusOneCaryOne"),x=new e.State({[o("^10")]:{command:{movement:e.movements.right}},[o("$")]:{command:{movement:e.movements.left},nextState:w},[e.ifOtherSymbol]:{nextState:e.haltState}},"plusOne"),N=new e.State({[o("^10")]:{command:{movement:e.movements.right}},[o("$")]:{nextState:i.withOverrodeHaltState(x.withOverrodeHaltState(i.withOverrodeHaltState(d)))},[e.ifOtherSymbol]:{nextState:e.haltState}},"minusOne");var O={getTapeBlock:function(){return m.clone()},states:{goToNumber:n,goToNextNumber:a,goToPreviousNumber:l,deleteNumber:v,goToNumbersStart:S,invertNumber:i,normalizeNumber:d,plusOne:x,minusOne:N}};module.exports=O;
package/dist/index.es.js DELETED
@@ -1 +0,0 @@
1
- import{Alphabet as e,TapeBlock as t,State as m,haltState as n,ifOtherSymbol as o,movements as a,symbolCommands as r}from"@turing-machine-js/machine";const l=new e({symbolList:" ^$01".split("")}),i=new t({alphabetList:[l]}),{symbol:b}=i,u=new m({[b("$")]:{nextState:n},[o]:{command:{movement:a.right}}},"goToNumber"),S=new m({[o]:{command:{movement:a.right},nextState:u}},"goToNextNumber"),s=new m({[b("$")]:{nextState:n},[o]:{command:{movement:a.left}}},"goToPreviousNumberTrue"),v=new m({[o]:{command:{movement:a.left},nextState:s}},"goToPreviousNumber"),d=new m({[b("^")]:{nextState:n},[o]:{command:{movement:a.left}}},"goToNumberStart"),c=new m({[b("$")]:{command:{symbol:r.erase},nextState:n},[o]:{command:{symbol:r.erase,movement:a.right}}},"deleteNumberTrue"),w=new m({[b("^10$")]:{nextState:d.withOverrodeHaltState(c)},[o]:{nextState:n}},"deleteNumber"),x=new m({[b("^")]:{command:{movement:a.right}},[b("1")]:{command:{symbol:"0",movement:a.right}},[b("0")]:{command:{symbol:"1",movement:a.right}},[b("$")]:{nextState:n}},"invertNumberGoToNumberWithInversion"),N=new m({[b("^10$")]:{nextState:d.withOverrodeHaltState(x)},[o]:{nextState:n}},"invertNumber"),g=new m({[b(l.blankSymbol)]:{command:{symbol:"^"},nextState:u}},"normalizeNumberPutNewStartSymbol"),h=new m({[b("^0")]:{command:{symbol:r.erase,movement:a.right}},[b("1$")]:{command:{movement:a.left},nextState:g}},"normalizeNumberMoveNumberStart"),y=new m({[b("^10$")]:{nextState:d.withOverrodeHaltState(h)},[o]:{nextState:n}},"normalizeNumber"),O=new m({[b("1")]:{command:{symbol:"0",movement:a.right}},[b("$")]:{nextState:n}},"plusOneFillZeros"),T=new m({[b(l.blankSymbol)]:{command:{symbol:"^",movement:a.right}},[b("1")]:{command:{movement:a.right},nextState:O}},"plusOneAddNumberStart"),$=new m({[b("0")]:{command:{symbol:"1",movement:a.right},nextState:O},[b("1")]:{command:{movement:a.left}},[b("^")]:{command:{symbol:"1",movement:a.left},nextState:T}},"plusOneCaryOne"),f=new m({[b("^10")]:{command:{movement:a.right}},[b("$")]:{command:{movement:a.left},nextState:$},[o]:{nextState:n}},"plusOne"),p=new m({[b("^10")]:{command:{movement:a.right}},[b("$")]:{nextState:N.withOverrodeHaltState(f.withOverrodeHaltState(N.withOverrodeHaltState(y)))},[o]:{nextState:n}},"minusOne");var H={getTapeBlock:function(){return i.clone()},states:{goToNumber:u,goToNextNumber:S,goToPreviousNumber:v,deleteNumber:w,goToNumbersStart:d,invertNumber:N,normalizeNumber:y,plusOne:f,minusOne:p}};export default H;