Sha256: 808167d43c30be5cd9efa77b1444fb9ac7276132b38710563b9b78b71aff5b3f

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

# Combinatorics

* [github.com/postmodern/combinatorics](http://github.com/postmodern/combinatorics)
* [github.com/postmodern/combinatorics/issues](http://github.com/postmodern/combinatorics/issues)
* Postmodern (postmodern.mod3 at gmail.com)

## Description

A collection of modules and methods for performing
[Combinatoric](http://en.wikipedia.org/wiki/Combinatoric) calculations.

## Features

* Adds `powerset` to {Array} and {Set}.
* Adds Haskell/Python style list comprehensions via {Array#comprehension}.

## Examples

Power-set of an {Array}:

    require 'combinatorics/power_set'

    [1,2,3,4].powerset
    # => [[],
          [4],
          [3],
          [3, 4],
          [2],
          [2, 4],
          [2, 3],
          [2, 3, 4],
          [1],
          [1, 4],
          [1, 3],
          [1, 3, 4],
          [1, 2],
          [1, 2, 4],
          [1, 2, 3],
          [1, 2, 3, 4]]

Power-set of a {Set}:

    Set['ab', 'cd', 'ef'].powerset
    # => [#<Set: {}>,
          #<Set: {"ef"}>,
          #<Set: {"cd"}>,
          #<Set: {"cd", "ef"}>,
          #<Set: {"ab"}>,
          #<Set: {"ab", "ef"}>,
          #<Set: {"ab", "cd"}>,
          #<Set: {"ab", "cd", "ef"}>]

List comprehensions:

    require 'combinatorics/list_comprehension'

    [(0..10).step(2),('a'..'c')].comprehension.to_a
    # => [[0, "a"],
          [0, "b"],
          [0, "c"],
          [2, "a"],
          [2, "b"],
          [2, "c"],
          [4, "a"],
          [4, "b"],
          [4, "c"],
          [6, "a"],
          [6, "b"],
          [6, "c"],
          [8, "a"],
          [8, "b"],
          [8, "c"],
          [10, "a"],
          [10, "b"],
          [10, "c"]]

## Install

    $ sudo gem install combinatorics

## License

See {file:LICENSE.txt} for license information.

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
combinatorics-0.1.0 README.md