0.0.12 • Published 12 months ago

@math-x-ts/generix v0.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

@math-x-ts/generix


Derived from the concepts of 'Generation' and 'Generator', the 'Generix' library is dedicated to the task of data generation based on provided inputs. For example you can use this library to generate combinations & permutations.

Note Generix was primarily designed for educational purposes, and as such, you may encounter certain limitations, such as memory issues. Other languages, like C or C++, might be more suitable for tasks of this nature due to their lower-level system access and more efficient memory management.

Installation

npm install --save @math-x-ts/generix

or

yarn add @math-x-ts/generix

Package content

  • Permutation class. Used to generated permutation with or without repetitions
  • Combination class. Used to generated combination with or without repetitions
import { Combination, Permutation } from '@math-x-ts/generix';

Usage

Combination without repetition

const result = Combination.withoutRepetition(['A', 'B', 'C']);
console.log(result);
[
    ['A', 'B', 'C']
]

Pick without repetition 1 element from the set 'A', 'B', 'C';

const result = Combination.withoutRepetition(['A', 'B', 'C'], 1);
console.log(result);
[
    ['A'],
    ['B'],
    ['C'],
]

Pick without repetition 2 elements from the set 'A', 'B', 'C';

const result = Combination.withoutRepetition(['A', 'B', 'C'], 2);
console.log(result);
[
    ['A', 'B'],
    ['A', 'C'],
    ['B', 'C'],
]

Pick without repetition between 2 and 3 elements from the set 'A', 'B', 'C', 'D';

const result = Combination.withoutRepetition(['A', 'B', 'C', 'D'], 2, 3);
console.log(result);
[
    ['A', 'B'],
    ['A', 'C'],
    ['A', 'D'],
    ['B', 'C'],
    ['B', 'D'],
    ['C', 'D'],
    ['A', 'B', 'C'],
    ['A', 'B', 'D'],
    ['A', 'C', 'D'],
    ['B', 'C', 'D'],
]

Combination with repetition

const result = Combination.withRepetition(['A', 'B', 'C']);
console.log(result);
[
    ['A', 'A', 'A'],
    ['A', 'A', 'B'],
    ['A', 'A', 'C'],
    ['A', 'B', 'B'],
    ['A', 'B', 'C'],
    ['A', 'C', 'C'],
    ['B', 'B', 'B'],
    ['B', 'B', 'C'],
    ['B', 'C', 'C'],
    ['C', 'C', 'C']
]

Pick with repetition 1 element from the set 'A', 'B', 'C';

const result = Combination.withRepetition(['A', 'B', 'C'], 1);
console.log(result);
[
    ['A'],
    ['B'],
    ['C'],
]

Pick with repetition 2 elements from the set 'A', 'B', 'C';

const result = Combination.withRepetition(['A', 'B', 'C'], 2);
console.log(result);
[
    ['A', 'A'],
    ['A', 'B'],
    ['A', 'C'],
    ['B', 'B'],
    ['B', 'C'],
    ['C', 'C'],
]

Pick with repetition between 2 and 4 elements from the set 'A', 'B', 'C';

const result = Combination.withRepetition(['A', 'B', 'C'], 2, 4);
console.log(result);
[
    ['A', 'A'],
    ['A', 'B'],
    ['A', 'C'],
    ['B', 'B'],
    ['B', 'C'],
    ['C', 'C'],
    ['A', 'A', 'A'],
    ['A', 'A', 'B'],
    ['A', 'A', 'C'],
    ['A', 'B', 'B'],
    ['A', 'B', 'C'],
    ['A', 'C', 'C'],
    ['B', 'B', 'B'],
    ['B', 'B', 'C'],
    ['B', 'C', 'C'],
    ['C', 'C', 'C'],
    ['A','A','A','A'],
    ['A','A','A','B'],
    ['A','A','A','C'],
    ['A','A','B','B'],
    ['A','A','B','C'],
    ['A','A','C','C'],
    ['A','B','B','B'],
    ['A','B','B','C'],
    ['A','B','C','C'],
    ['A','C','C','C'],
    ['B','B','B','B'],
    ['B','B','B','C'],
    ['B','B','C','C'],
    ['B','C','C','C'],
    ['C','C','C','C']

]

Permutation without repetition

const result = Permutation.withoutRepetition(['A', 'B', 'C']);
console.log(result);
[
    ['A','B','C'],
    ['A','C','B'],
    ['B','A','C'],
    ['B','C','A'],
    ['C','A','B'],
    ['C','B','A']
]

Pick without repetition 2 elements from the set 'A', 'B', 'C';

const result = Permutation.withoutRepetition(['A', 'B', 'C'], 2);
console.log(result);
[
    ['A','B'],
    ['A','C'],
    ['B','A'],
    ['B','C'],
    ['C','A'],
    ['C','B']
]

Pick without repetition between 2 and 3 element from the set 'A', 'B', 'C';

const result = Permutation.withoutRepetition(['a', 'b', 'c'], 2, 3);
console.log(result);
[
    ['a','b'],
    ['a','c'],
    ['b','a'],
    ['b','c'],
    ['c','a'],
    ['c','b'],
    ['a','b','c'],
    ['a','c','b'],
    ['b','a','c'],
    ['b','c','a'],
    ['c','a','b'],
    ['c','b','a']
]

Permutation with repetition

const result = Permutation.withRepetition(['A', 'B']);
console.log(result);
[
    ['A','A'],
    ['A','B'],
    ['B','A'],
    ['B','B']
]

Pick with repetition 2 elements from the set 'A', 'B', 'C';

const result = Permutation.withRepetition(['A', 'B', 'C'], 2);
console.log(result);
[
    ['A','A'],
    ['A','B'],
    ['A','C'],
    ['B','A'],
    ['B','B'],
    ['B','C'],
    ['C','A'],
    ['C','B'],
    ['C','C']
]

Pick with repetition between 2 and 3 elements from the set 'A', 'B';

const result = Permutation.withRepetition(['A', 'B'], 2, 3);
console.log(result);
[
    ['A','A'],
    ['A','B'],
    ['B','A'],
    ['B','B'],
    ['A','A','A'],
    ['A','A','B'],
    ['A','B','A'],
    ['A','B','B'],
    ['B','A','A'],
    ['B','A','B'],
    ['B','B','A'],
    ['B','B','B']
]
0.0.12

12 months ago

0.0.11

12 months ago