Project

## cartesian

0.01
No commit activity in last 3 years
No release in over 3 years
Provides methods for the calculation of the cartesian producted between two or more enumerable objects. Includes grid search optimization methods. It can also be easily and conveniently mixed in into any enumerable class.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
Dependencies

~> 3.4
>= 1.5.3
~> 3.10

# cartesian¶ ↑

## DESCRIPTION:¶ ↑

Provides methods for the calculation of the cartesian producted between two or more enumerable objects. Includes grid search optimization methods. It can also be easily and conveniently mixed in into any enumerable class.

## FEATURES:¶ ↑

The module is automatically mixed in Array class, but the names of the methods for mixin are different.

Module:

```Cartesian::product(foo, bar)
```

Mixin:

```foo.cartesian( bar )
```

## SYNOPSIS:¶ ↑

One can use the Cartesian module directly

```require 'cartesian'
foo = [1, 2]
bar = ["a", "b"]
Cartesian::product(foo, bar) #=> [[1, "a"], [1, "b"], [2, "a"], [2, "b"]]
```

or use the methods provided by the mixin in the Array class

```foo.cartesian(bar)  #=> [[1, "a"], [1, "b"], [2, "a"], [2, "b"]]
```

which include the short'n'sweet x method

```v = [] #=> []
for a, b in [1,2].x [3,4]
v << [a,b]
end #=> true
v #=> [[1, 3], [1, 4], [2, 3], [2, 4]]
for x, y, z in 0..1```

The '**' operator provides a convenient way of iterating multi-dimensionally over the same array or range

```u = [0,1]**3 #=> #<CartesianIterator:0x7f2fb8e54978 @tot_iter=8, @lists=[[0, 1], [0, 1], [0, 1]]>
u.to_a #=> [[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]]

v = []
for x, y, z in (0...10)**3
v << [x, y, z] if x*x + y*y + z*z == 6
end
v #=> [[1, 1, 2], [1, 2, 1], [2, 1, 1]]
```

Finally, the grid search methods

```require 'cartesian/grid_search'
[-1, 0, 1, 2].argmax {|x| x**2 } #=> 2
[-1, 0, 1, 2].argmin {|x| x.abs } #=> 0
```

## REQUIREMENTS:¶ ↑

• None, besides the Ruby interpreter and standard library. This gems was successfully tested on all relevant Ruby versions: MRI/YARV, JRuby, Rubinius, and REE. For details, see History.txt.

## INSTALL:¶ ↑

• sudo gem install cartesian