Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A little gem that gives you all partitions of an array into at most k sub-arrays
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
example
lib
spec
.gitignore
README.md
array_partition.gemspec

README.md

Array Partition

by Aish Fenton for vWorkApp

A little gem that gives you all partitions of an array into at most k sub-arrays. Useful for generating test scenarios and solving certain kinds of optimisation problems.

require 'array_partition'
["Apple", "Orange", "Pear"].partition(2)

[
    [["Apple", "Orange", "Pear"]], 
    [["Apple", "Orange"], ["Pear"]], 
    [["Apple", "Pear"], ["Orange"]], 
    [["Apple"], ["Orange", "Pear"]]
]

The gem can also be used to provide the Stirling Number of the Second Kind of the array.

Install

sudo gem install array_partition

Usage

See example/fuel_tanker.rb for a real-life application of partitions being used to solve a combinatorial optimisation problem.

Copyright

Copyright (c) 2011 vWorkApp Inc.

Something went wrong with that request. Please try again.