ComboData

Analyze a data set for combinations summing to a given value.

Analyze a data set for pairs with a difference of a given value.

Installation

Add this line to your application's Gemfile:

gem 'combo_data'

And then execute:

$ bundle

Or install it yourself as:

$ gem install combo_data

Usage

Create a ComboData::DataSet object with an array of values:

data_set = ComboData::DataSet.new((1..1000).to_a)

Analyze the data set for combinations summing to a given value.

data_set.combinations_summing_to 20
=> {[1, 19]=>20, [2, 18]=>20, [3, 17]=>20, [4, 16]=>20, [5, 15]=>20, [6, 14]=>20, [7, 13]=>20, [8, 12]=>20, [9, 11]=>20, [20]=>20}

Change the max combination length:

data_set.max_combination_length = 3 # defaults to 2
=> 3
hate.combinations_summing_to 20
=> {[1, 2, 17]=>20, [1, 3, 16]=>20, [1, 4, 15]=>20, [1, 5, 14]=>20, [1, 6, 13]=>20, [1, 7, 12]=>20, [1, 8, 11]=>20, [1, 9, 10]=>20, [2, 3, 15]=>20, [2, 4, 14]=>20, [2, 5, 13]=>20, [2, 6, 12]=>20, [2, 7, 11]=>20, [2, 8, 10]=>20, [3, 4, 13]=>20, [3, 5, 12]=>20, [3, 6, 11]=>20, [3, 7, 10]=>20, [3, 8, 9]=>20, [4, 5, 11]=>20, [4, 6, 10]=>20, [4, 7, 9]=>20, [5, 6, 9]=>20, [5, 7, 8]=>20, [1, 19]=>20, [2, 18]=>20, [3, 17]=>20, [4, 16]=>20, [5, 15]=>20, [6, 14]=>20, [7, 13]=>20, [8, 12]=>20, [9, 11]=>20, [20]=>20}

Analyze the data set for pairs with a difference of a given value.

data_set.pairs_with_a_difference_of 997
 => {[1, 998]=>997, [2, 999]=>997, [3, 1000]=>997} 

Change the timeout for processing:

data_set.timeout = 120 # seconds, defaults to 60
=> 120

Change the precision while making comparisons:

data_set.precision = 3 # decimal places
=> 3

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request