Tool for working with a custom numeric code system.
The numeric code is made up of digits from 1 to 9 inclusively. 0 and any
other symbol can be included, but will be ignored when processing.
Ex: 091230/129830
This numeric code system can be used to denote positions of elements in a game
using 0 for empty spaces.
For example, we could use this code 00210/00211/00210/00211/00200 to denote a
the following go position on a 5 x 5 board. The numbers 1 and 2 could denote
the black and white stone colors. We could then obtain a canonicalization or a
randomization of the position using this module.
0 0 2 1 0
0 0 2 1 1
0 0 2 1 0
0 0 2 1 1
0 0 2 0 0
https://www.npmjs.com/package/@pelevesque/numeric-code
npm install @pelevesque/numeric-code
npm test
npm run cover
canonicalizecanonicalizes a numeric coderandomizerandomizes a numeric code
const numericCode = require('@pelevesque/numeric-code')const numericCode = require('@pelevesque/numeric-code').canonicalizeCanonicalizing the numeric code does two things:
- The code is flattened to avoid jumps between digits.
- The code is ordered chronologically.
const str = '008213/923480'
const result = numericCode.canonicalize(str)
// result === '001234/524610'Randomizing the numeric code does two things:
- The code is flattened to avoid jumps between digits.
- The code is ordered randomly.
const str = '008213/923480'
const result = numericCode.randomize(str)
// result === '004312/532640'