# Permutations that include sub-arrays in ruby?

**URL:** <https://www.ruby-forum.com/t/permutations-that-include-sub-arrays-in-ruby/189595>\
**Category:** Ruby\
**Created:** [June 3, 2010, 6:06pm UTC](https://www.ruby-forum.com/t/permutations-that-include-sub-arrays-in-ruby/189595 "2010-06-03T18:06:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Todd\_ASJacobs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@Todd\_ASJacobs](https://www.ruby-forum.com/u/Todd_ASJacobs)\
**Post date:** [June 3, 2010, 6:06pm UTC](https://www.ruby-forum.com/t/permutations-that-include-sub-arrays-in-ruby/189595/1 "2010-06-03T18:06:44Z")

</div>

Ruby has a terrific implementation of single-valued permutations, but it  
doesn’t yield the results I expected when using arrays of arrays. For  
example:

```
[[1, 2], [2, 3]].permutation.to_a.include? [2, 1]
=> false

```

The reason is that there’s no permutation of the sub-arrays, just of the  
top-level array elements. Am I overlooking something obvious here? I’d  
like the permutations to include randomization within each sub-array,  
too.

---

<div class="post-metadata">

**Author:** ![Todd\_ASJacobs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@Todd\_ASJacobs](https://www.ruby-forum.com/u/Todd_ASJacobs)\
**Post date:** [June 3, 2010, 7:00pm UTC](https://www.ruby-forum.com/t/permutations-that-include-sub-arrays-in-ruby/189595/2 "2010-06-03T19:00:01Z")

</div>

On Fri, Jun 4, 2010 at 12:04 AM, Todd A. Jacobs  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The reason is that there’s no permutation of the sub-arrays, just of the  
> top-level array elements.

you assumed that it has _only_ sub-arrays

consider eg,  
[[1, 2], :a, String, 3].permutation.to\_a

> Am I overlooking something obvious here? I’d  
> like the permutations to include randomization within each sub-array,

just include permutation of the sub then

kind regards -botp
