Noisy Pneumatic Mnemonic

    lexicographer

    1.0.1 • Public • Published

    Build Status devDependencies Status

    Lexicographer

    Lexicographer is a lexicographic permutation generator created as a direct result of Project Euler's twenty-fourth problem.

    One time, many years ago during my first pass through Project Euler, this problem owned the shit out of me. Like, badly owned me. For the life of me I couldn't make the mental translation from mathematical method to functional algorithm. I gave up in the end, and used a solution scalped from some random website.

    Well, fuck that noise.

    This is a fully-functional functional lexicographic permutation generator generator. It doesn't use some fancy algorithm or mathematical inside to jump to the solution of the exercise. No, fuck that. This code owns the shit out of the entire problem of lexicographic permutation in an over-engineered way. There are test suites and comment blocks and examples and recursive README files full of foul-mouthed trash talk.

    Installation

    npm install lexicographer
    

    Testing

    npm run test
    

    Usage

    (This also solves problem 24.)

    #!/usr/bin/env node
     
    const lexicographer = require('lexicographer');
    const array = [...Array(10).keys()];
    const breakpoint = 1000000;
    let permutations = 0;
     
    for (let value of lexicographer.permute(array)) {
        permutations++;
     
        if (permutations === breakpoint) {
            console.log(value.join(''));
            break;
        }
    }

    Copyright

    Copyright (c) 2016 Mark Grealish. See LICENSE for details.

    Install

    npm i lexicographer

    DownloadsWeekly Downloads

    2

    Version

    1.0.1

    License

    MIT

    Last publish

    Collaborators

    • bhalash