Giter Club home page Giter Club logo

cagen's Introduction

Cagen

GitHub license npm version Downloads Build Status

Number of Case Generator for TypeScript.

Symbol Class
A x B x ... x Z CartesianProduct
n! Factorial
nPr Permutation
nโˆr RepeatedPermutation
nHr RepeatedCombination
nCr Combination

Usage

Installation

npm install --save cagen

Common Features

namespace cagen.base
{
    export interface IForwardGenerator
    {
        // FREQUENCE ACCESSORS
        size(): number;
        begin(): Iterator;
        end(): Iterator;

        // ES2015, THEN FOR-OF ITERATION IS ALSO POSSIBLE
        [Symbol.iterator]: IterableIterator<number[]>;
    }

    export interface Iterator
    {
        readonly value: number[];

        next(): Iterator;
        equals(obj: Iterator): boolean;
    }
}
import { CartesianProduct } from "cagen";

function main(): void
{
    let generator = new CartesianProduct(5, 4); // 5C4
    console.log("n(5C4) =", generator.size());

    for (let it = generator.begin(); !it.equals(generator.end()); it = it.next())
    {
        let aCase: number[] = it.value;
        console.log("  -", aCase);
    }
}
main();
for (let aCase of generator)
    console.log("  -", aCase);

Random Accessor

namespace cagen.base
{
    export abstract class ArrayGenerator
        implements IForwardGenerator<Iterator>
    {
        at(index: number): Array<number>;
    }
}

Most of Case Generator classes, except combination classes, provide a random accessor at(). By that method at(), you can access to a specific case through not full iteration, but the special index number.

  • Permutation
  • Factorial
  • RepeatedPermutation
  • CartesianProduct
  • Combination
  • RepeatedCombination
import { Permutation } from "cagen";

function main(): void
{
    let generator = new Permutation(7, 3);

    console.log( generator.at(13) );
    console.log( generator.at(31) );
    console.log( generator.at(9999) ); // throw an std.OutOfRange error.
}
main();

cagen's People

Contributors

samchon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

fossabot

cagen's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.