Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

lexicographic-generator

1.0.2 • 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 lexicographic-generator

Downloadsweekly downloads

0

version

1.0.2

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability