npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@math-x-ts/generix

v0.0.12

Published

This library tasks is to generate combinations and permutations

Downloads

9

Readme

@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']
]