Socket
Book a DemoInstallSign in
Socket

@math-x-ts/generix

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@math-x-ts/generix

This library tasks is to generate combinations and permutations

0.0.12
latest
Source
npmnpm
Version published
Weekly downloads
2
-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

@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);
Output
[
    ['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);
Output
[
    ['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);
Output
[
    ['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);
Output
[
    ['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);
Output
[
    ['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);
Output
[
    ['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);
Output
[
    ['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);
Output
[
    ['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);
Output
[
    ['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);
Output
[
    ['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);
Output
[
    ['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);
Output
[
    ['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);
Output
[
    ['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);
Output
[
    ['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']
]

Keywords

Generation

FAQs

Package last updated on 13 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.